Possible windows bug in "QStandardPaths"?
-
@ademmler said in Possible windows bug in "QStandardPaths"?:
Does this mean I always add a "/" - on all platforms - to paths - if I have to?
Dummy example:
QString myDesktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
QString myWorkingDir = myDesktopPath + "/" + "Jobsfolder"
....
And how do I properly quote "Spaces" in paths than?As written in QDir documentation, Qt always use internally '/' as path separator.
There are many help functions to work with path.
Your dummy example:QString myDesktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); QString myWorkingDir = QDir(myDesktopPath).filePath("Jobsfolder");
When you need to use the path for external "tools" (for example as parameter for a QProcess), you should use
QDir:toNativeSeparators()
so you don't have to carry about the path separator. -
@KroMignon said in Possible windows bug in "QStandardPaths"?:
QDir(myDesktopPath).filePath("Jobsfolder");
Last question about all this:
On Mac OS X app resources are in the bundle package "Resources" folder.
I would do QDir(QApplication::applicationDirPath()).filePath("../Resources"); than. -
@ademmler said in Possible windows bug in "QStandardPaths"?:
QDir(QApplication::applicationDirPath()).filePath("../Resources")
Be careful. I don't know anything about Mac or " in the bundle package "Resources" folder.". Is
Resources
a real, physical sub-directory located (one directory above?) your application directory, or is it purely an internal reference to the resources embedded in the executable? -
@ademmler said in Possible windows bug in "QStandardPaths"?:
I would do QDir(QApplication::applicationDirPath()).filePath("../Resources"); than
I would do it like this:
QDir resourcesPath(QApplication::applicationDirPath()); resourcesPath.cd("../Resources"); // now you can use resourcesPath to get files from your resources directory.
-
Ihm using this to get the appbundle path on Mac OS and the executable path on the other platforms
static const QString &ApplicationFolder (){ #ifdef Q_OS_MACOS auto getStringPath = []()->QString{ CFURLRef url =(CFURLRef)CFAutorelease((CFURLRef)CFBundleCopyBundleURL(CFBundleGetMainBundle())); QDir d(QUrl::fromCFURL(url).path()); d.cdUp(); return d.absolutePath(); }; static const QString path = getStringPath(); #else static const QString path = QCoreApplication::applicationDirPath(); #endif return path; }
-
@J-Hilk thx for your suggestion.
I tried this way - because it is platform independent. On top using a QDir objects is giving lots of other handy functionality like .exists(); .remove(); .removeRecursively() and others.
QDir resourcesPath = QDir(QApplication::applicationDirPath()); #if defined Q_OS_MACX resourcesPath.cd("../Resources"); #else resourcesPath.cd("resources"); #endif