[SOLVED] QDir with a QResource path is not initialized in the constructor
-
Hello,
I have the following problem :
@
MyClass.h
...
private:
...
QDir m_iconsResourcePath;QFile m_codesFile;
@
@
MyClass.cppMyClass::MyClass(QStandardItemModel *model)
:m_languagesModel(model)
,m_iconsResourcePath(":/Icons/languages")
,m_codesFile(":/Codes/codes.txt")
@The QDir is not initialized but the QFile is. The QResource paths and prefixes are double-checked so they point to the right places. Initializing the QDir with an absolute file system path works fine too.
Any ideas what am I doing wrong?
Thanks
Edit: Clarified the title a little :-)
-
Seems indeed strange. Try passing "qrc:/Icons/languages"), or construct the path with QUrl.
Is this in Qt4 or Qt5?
-
Thanks for your reply sierdzio.
I found the problem, although I don't understand why is happening. The weirdness with the path occurs when I try to use the resources in a separate library that I link statically in the main app. If I move the resources from the library's .pro file to the main app's .pro file, then the constructor in the library works fine... I would still prefer to use these resources in the separate library though.
This is Qt5 on OS X and Linux.
-
Did you read "Using Resources in the Application":http://qt-project.org/doc/qt-5.0/qtcore/resources.html#using-resources-in-the-application and try?
From doc:
@
/*
If you have resources in a static library, you might need to force initialization of your resources by calling Q_INIT_RESOURCE() with the base name of the .qrc file. For example:
*/int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Q_INIT_RESOURCE(graphlib);
...
return app.exec();
}
@
Maybe this help.