Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QDir with a QResource path is not initialized in the constructor
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QDir with a QResource path is not initialized in the constructor

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    panosk
    wrote on last edited by
    #1

    Hello,

    I have the following problem :
    @
    MyClass.h
    ...
    private:
    ...
    QDir m_iconsResourcePath;

    QFile m_codesFile;
    

    @

    @
    MyClass.cpp

    MyClass::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 :-)

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Seems indeed strange. Try passing "qrc:/Icons/languages"), or construct the path with QUrl.

      Is this in Qt4 or Qt5?

      (Z(:^

      1 Reply Last reply
      0
      • P Offline
        P Offline
        panosk
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hostel
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            panosk
            wrote on last edited by
            #5

            Apparently I missed that part in the doc... It works fine now.

            Thank you Hostel.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved