[SOLVED] using the prefix in a resource file
using QDir::homePath() display the path of home directory for every user.
how do i put a prefix in the resource file using the home directory of the user?
windows: c:\Documents and Settings\username
You don't. The files you use are encoded into a cpp file resulting from the rcc tool. They are then compiled into your program. The prefix is used for making (logical) separations between groups of images/whatever.
so i have to use :
QDir::homePath() + url.toLocalFile();
What exactly do you want to achieve?
Access to resources is done this way:
QFile f (":/myPrefix/mySubprefeix/name");
the ":" in the beginning tells qt to use the resources.
If you want to load an image from a certain location, use QDir::homePath(), QUrl or whatever is required (QFileDialog, QDesktopServices). If you need an image in your resource file, use the resource editor to add it and let Qt handle it. You don't need access to the home dir then.
im putting configuration files in the home directory.
the QFile cant read the file unless i put the file in the current folder.
windows: c:\Documents and Settings\username\Application Data\myapp\files.ext
On both platforms?
Why not use QSettings?
In that case, you should look into the QDesktopServices class. It will supply you with a cross platform way to query for locations on disk like this. In your case, you are probably looking for QDesktopServices::DataLocation.
Note that inside your Qt program, you should use forward slashes for all file paths, even on Windows. Only for paths you display to the user, you can use QDir::toNativeSeparators to get the native format.
Franzk: i cant use QSettings cause i need to save the configurations to a file so i could load it again using the QFile then use QSettings.
Andre: i think ill try QDesktopServices::DataLocation. it seems that this directory is where my configurations files to be stored.
[quote author="xeroblast" date="1299583686"]Franzk: i cant use QSettings cause i need to save the configurations to a file so i could load it again using the QFile then use QSettings.[/quote]
QSettings can do ini files. You just have to explicitly tell it to do that on windows. On linux the settings are stored in ~/.config/.
[quote author="Franzk" date="1299585456"]QSettings can do ini files. You just have to explicitly tell it to do that on windows. On linux the settings are stored in ~/.config/.[/quote]
ok. i think this is what i want. i just didnt know where the ini files located. i thought QSettings didnt saved it.
so in windows, where is the ini files located?
It saves them where you tell it to save them. By default it will go for registry, but there's the option of setting the format and file: http://doc.trolltech.com/latest/qsettings.html#QSettings-4
thanks for the info...
shadow.seeker last edited by
Resolved mine also. thanks again.
Can there be a small an example put in the list also. Would help lot as most of us spend loads of time searching it.