Qt 5.2 Including External File into an Android Package? - qt

How to include an external file into 'apk' ?
Example:
There is "123.txt" in the main directory where .pro file exists. What should I add to pro file to put "123.txt" into apk.
I tried DEPLOYMENT, DEPLOYMENTFOLDERS. But they only works with Symbian and Windows CE.

There are two ways to do it, both mentioned under "Porting an Existing Qt Application" on Qt 5.1 Documentation For Android.
Bundle them into a qrc file (works cross platform)
Add them to the "assets:" directory (Android specific)
For #2:
The "assets" directory will be created when you build the project. I have found it easiest to use the "INSTALLS" qmake variable to copy the files into the directory before it is packaged into an apk. The following is from a qmake file for a project I made. Note that for INSTALLS, the path to assets reads "/assets", not "assets" as you would expect. (It actually ends up in a subdirectory of the Android build workspace.)
To access the directory from the code in android, you use "assets:". (In the example, /assets/Samples ==> assets:/Samples.)
# - setup the correct location to install to and load from
android {
# android platform
# From: http://community.kde.org/Necessitas/Assets
SAMPLES_INSTALL_PATH=/assets/Samples
} else {
# other platforms
SAMPLES_INSTALL_PATH=$$OUT_PWD/Samples
}
# - setup the 'make install' step
samples.path = $$SAMPLES_INSTALL_PATH
samples.files += $$SAMPLE_FILES
samples.depends += FORCE
INSTALLS += samples

You can use the Qt Resource system. By default, all Qt applications can access the contents of a qrc file using the ":/" prefix or the URL scheme prefix, "qrc:".
The other approach is to deploy the resources into the package's assets directory. It is the best option if you want to achieve better interoperability with the Android APIs. You can access all resources in the directory using the "assets:" prefix. Unlike qrc, this approach is not a cross-platform solution.
When you build your project, a folder named "assets" is created in the Build-Directory/android-build/. After copying your files in the assets directory, you can add these to your pro:
deployment.files += MyFile1
deployment.files += MyFile2
...
deployment.path = /assets
INSTALLS += deployment
The files in assets are readonly. So you should first copy it to some other location if you want to change them:
QFile dfile("assets:/MyFile1");
if (dfile.exists())
{
dfile.copy("./MyFile1");
QFile::setPermissions("./MyFile1",QFile::WriteOwner | QFile::ReadOwner);
}

Specific to User2400925
In QT 5.1 I had used to copy the database from Assets folder to the home folder of the user, if the file does not exist. Which can be used by the App.
You may go through this link

One more simple way to do that:
1) Add this string into your .pro
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
2) Create android-sources folder in your proj folder. Put anything you need into android-sources/assets/. You can also put there any other files, such as AndroidManifest.xml or android-sources/res/drawable/icon.png that you want to be copied and updated into the target bundle.

One more simple way to do that:
Add this string into your .pro
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
Create android-sources folder in your proj folder. Put anything you need into android-sources/assets/. You can also put there any other files, such as AndroidManifest.xml or android-sources/res/drawable/icon.png that you want to be copied and updated into the target bundle.

Related

Qt renaming path of the project

sometimes when I rename the path to a qt project, it cannot be run even though I clean qmake and rebuild it!!! the path does not contain any space. and the project is completely correct and I know that the error is for path renaming , for example when I rename :
D:/abd/projects/LAND_2/Land_QT/...
to
D:/abd/projects/LAND_2/Land2_QT_SA/...
it cannot be build and says that some include file is missing(but the file is there!).
what is the problem?
I work with dynamic qt5.2 on windows 7.
Edit:
when I copy the project folder to a new directory( a path upper than current path) then the project can be build and run.
When you rename the path to the project, go to the project folder and delete the file with .pro.user extension. Open the project and Qt will ask you to configure the project. Choose the required kit, build and run the project.It should build successfully now
If you have changed path multiple times the .pro.user file is created multiple times delete all files with this extension and compile

How to deploy audio/video files together with iOS/Android app? Using Qt 5.3

I have learned that I can not bundle audio/video files within resource file in order to play them in my qml.
So, I have tried to use DEPLOYMENTFOLDERS in .pro file it does not copy the files.
It seems that QtCreator does not generate necessary code contents using DEPLOYMENTFOLDERS in .pri file.
Is there an easy way to say copy these files into build output location?
Visual studio C# has this option just saying one true/false to do this.
It should not be this hard. :-)
"Is there an easy way to say copy these files into build output location?" - this is a different task. You may achieve that with QMAKE_POST_LINK and writing a Makefile rule to copy the required files to the the output directory.
To copy the required file into the iOS bundle use QMAKE_BUNDLE_DATA. See https://qt-project.org/doc/qt-5-snapshot/platform-notes-ios.html
To copy the required file into the Andoid APK you need to write INSTALLS rules like that:
android {
...
assets.path = /assets
assets.files += LIST_OF_FILES
INSTALLS += assets
}

How to create a qt application for all unix versions?

I have been able create an application that depends on webkit and scripts in Qt5.2.1.But i was able to create a deb package for 14.04 version Ubuntu .But how can i make it as stand alone application .I have seen static and dynamic build .I tried static build but I don't kon w how to include webkit for static build.Also is it possible with shared library approach for creating a standalone application.Please help me out here..
Deploying a dynamically linked Qt application :
You should place Qt so files along the release version of your executable. These are libQtCore.so, libQtGui.so and possibly the ones for other modules that you have used. These so files are in your installed Qt directory in lib folder or in the directory /usr/lib/i386-linux-gnu. If you are using plugins you should place their so files in a folder named plugins beside your binary. In case of using icons and images you should ship their so files like libqico.so and libqsvg.so in a folder named imageformats.
Gathering required shared libraries :
If you want your application to run independently on a bare installed Linux, you should gather all dependent shared libraries and put them in your application directory. You can simply do it by a shell script named cpld. You can easily copy all dependencies to a folder.
It's worthy to note that you can put this in your .pro file to cause the dynamic linker to look in the same directory as your Qt application at runtime in Linux :
unix:{
# suppress the default RPATH if you wish
QMAKE_LFLAGS_RPATH=
# add your own with quoting gyrations to make sure $ORIGIN gets to the command line unexpanded
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
}

How ca I add static lib to blackberry 10 project?

I have a static lib (mylib.a).
How can I add it to the project (Momentic IDE)?
I treid to add it to lib folder and write
LIBS += -Bstatic -L/app/native/lib -mylib -Bdynamic \
to the file .pro, but it doesn't work
Right click on your project, select Configure -> Add Library from the menu.
On the dialog select External Library then Next. Browse to the locations for the device and simulator builds of the library, and add paths to the include directories. If it is a static library you may have to go into the bar-descriptor.xml file and remove asset entries for a dynamic library mylib.so. The reason for this is static libraries are linked at compile time, where as dynamic libraries that are not included with the OS must be loaded as assets with the application.
You need -*l*mylib. If that does not solve your problem, try to use absolute path for the static library.

Copy file to destination directory in Qt Creator

I want to copy a data file from a directory in my source tree to the directory of the linked app so it's available at runtime, on Windows only. There appear to be two suggested techniques: use a post target dependency to issue a DOS copy command (Including resource files in Qt Creator build directory) or use an install step (Copy a file to the build directory after compiling project with Qt), but I cannot make either work in the way I would like.
The former requires me to use qmake path variables to generate my source and destination paths, but they contain backslash path separators, which the DOS copy command cannot handle.
The install solution forces other users of my project to set up a post build step in Qt Creator before it will work (one per configuration, in fact) and I would like to avoid this, as I want to make my project work with a default Qt Creator installation.
Is there any way to do this apparently simple task that can be wholly defined in the .pro file for the project? For example, is there a way to expand qmake path variables in a platform specific way?
Though these commands run ONLY after the executable is ACTUALLY linked, this solution doesn't require an external batch file. Note: this a Windows-only solution:
From our .pri file:
win32 {
...
# Copy the appropriate dll files into the target destination directory.
QMAKE_TBB_LIBDIR = $$quote($$PWD/MySource/MyLibs/$${PLATFORM_NAME}/vc9)
QMAKE_POST_LINK = copy /y $${replace(QMAKE_TBB_LIBDIR, /, \\)}\\*.dll > $${replace($$quote(DESTDIR), /, \\)}
...
}
This places a command in the Makefile that copies all the .dll files in MyLibs/x64 or MyLibs/Win32 into the destination directory.
However, if the executable did not need to be linked, then the .dlls are NOT copied.
The post build batch file would not have this limitation.

Resources