Finding config files in Android runtime deployments (Qt6.9.1)
-
I am trying to access a simple config file (Config.conf) from my Qt6 Android App.
It was suggested I add:
android {
my_files.path = /assets
my_files.files = $$PWD/etc/Config.conf
INSTALLS += my_files
}To my QtTest4.pro file this results in the file being included in my Apk file, if I unpack the Apk file (/tmp/MyApp) and do a file search I get:
find . -name Config.conf
./assets/Config.confIf I grep through the files under /tmp/MyApp I find:
./META-INF/MANIFEST.MF:Name: assets/Config.conf
./META-INF/KEY1.SF:Name: assets/Config.confSo I belive my config file is part of the Apk file for deployment.
When I debug my App at the point of opening the config file my working directory is:
"/data/data/com.home.QtTest4/files"
But the open always returns "no such file or directory" I have tried various prefixes for my config file but non have worked.
My question is:
Relative to my working directory where is the Config.conf file located ?
Thanks
-
Hi @SMF-Qt,
please format your code properly, using the </> code tags.
Please also post the code around and including the call tofopen()
. -
Hi @SMF-Qt,
please format your code properly, using the </> code tags.
Please also post the code around and including the call tofopen()
.This is the essence of the code I am using errno is returning 2 (no such file or directory).
I have tried adding various directory prefixes but no luck yet, works fine on linux.... const char *name="Config.conf"; ... int fd=open(name, O_RDONLY, 0640); if (fd<0) return errno; ...
On linux I use "/etc/connect/Config.conf" but that is not relevant under Android.
-
Hi,
With QFile you could use the
assets:/
prefix and it would get you what you want.
See here. -
Correct (and fixed) but don't assume, check the doc linked ;-)
-
First and foremost, as already said by @SGaist , I would really recommend to use the resource file system instead of trying to deploy files manually.
This can be confusing at times. The Swiss army knife to figure out how to access your resources is a three-liner.
You can add it to yourmain.cpp
in order to print a list of all existing resource files:QDirIterator it(":", QDirIterator::Subdirectories); while (it.hasNext()) qInfo() << it.next();
-
First and foremost, as already said by @SGaist , I would really recommend to use the resource file system instead of trying to deploy files manually.
This can be confusing at times. The Swiss army knife to figure out how to access your resources is a three-liner.
You can add it to yourmain.cpp
in order to print a list of all existing resource files:QDirIterator it(":", QDirIterator::Subdirectories); while (it.hasNext()) qInfo() << it.next();
@Axel-Spoerl said in Finding config files in Android runtime deployments (Qt6.9.1):
QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext())
qInfo() << it.next();Thanks for that but I see files I have in my images directory and stuff from the qt project but nothing from :/assets, but as I said the file is there if I unpack the Apk file.
Do I need to add something to the AndroidManifest.xml or my qrc file ?