[SOLVED] QDir not cd'ing on Mac OS Yosemite
-
Working on an app that needs to cd based off the QCoreApplication::applicationDirPath()
can get the path to application, but can not cd any where, not even cdUp()...
I have looked for known issues, but did not have any luck... surely this is something simple blocking me...Thanks in advance for any thoughts.
EB
-
QDir dir(QCoreApplication::applicationDirPath());
if (!dir.exists())
qWarning("Cannot find the APP directory");
qWarning("DEBUG: 1. app dir: %s", qPrintable(dir.currentPath()));qWarning("DEBUG: 1a readible?: %s", (dir.isReadable() ? "YES" : "NO" )); qWarning("DEBUG: 1b absolute?: %s", (dir.isAbsolute() ? "YES" : "NO" )); //dir.cdUp(); // was looking into this being an issue of the actual binary being buried in the app package //dir.cdUp(); //dir.cdUp(); if (!dir.exists("plugins")) qWarning("Cannot find the PLUGINS directory"); //dir.cd("plugins"); //qWarning("DEBUG: 2.app dir: %s", qPrintable(dir.currentPath())); //if (!dir.cd(QStringLiteral("plugins"))) { if (!dir.cd("plugins")) { /// TODO: Better error reporting qWarning("WARNING: Cannot find plugins!"); return; }
-
You could try another method. I am a little skeptical that QDir::cdUp() doesn't work but I didn't try it (maybe something related to being inside an app folder ?).
This will get the folder of the application (assuming the extension is '.app' which should be safe). A variation of this would be to get a specific folder in the application bundle of the container as opposed to trying to move up from the actual application itself.
QString d_data_path = qApp->applicationDirPath(); // remove everything past '.app' int index = d_data_path.lastIndexOf(".app/"); d_data_path.truncate(index); // remove name of application, whatever it is called index = d_data_path.lastIndexOf('/'); d_data_path.truncate(index);
It may be possible to get the 'plugins' folder by some other means. I know Qt can find it when the application is packaged properly (using macdeployqt).
One last thought. If you didn't package the application (manually or using macdeployqt) then you may not have a plugins folder inside the application. You should manually check to see it exists inside the application bundle.
-
You can check your directory by doing:
qDebug() << dir.absolutePath(); dir.cdUp(); qDebug() << dir.absolutePath();
That should tell you what's happening and why. I have used QDir specifically to navigate inside bundles on Mavericks and it worked so check what those values are and it might show you the problem.