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. Resource problem with cmake
Forum Updated to NodeBB v4.3 + New Features

Resource problem with cmake

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.4k 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.
  • F Offline
    F Offline
    fandras90
    wrote on last edited by
    #1

    Hi everyone,

    I am building a desktop app with Qt 5.3.1 and cmake 3, and have some troubles with the resources. I have a .qss file which works fine when loading directly from main.cpp, but when it comes to using resources, it does not work.

    I have one .qrc file in the same folder as the main.cpp, and added the .qss file in the qrc , my code is the following:

    @<RCC>
    <qresource prefix="/">
    <file>Resources/ScStyleSheet.qss</file>
    </qresource>
    </RCC>@

    My code in main.cpp :

    @ QFile File(":/ScStyleSheet.qss");
    File.open(QIODevice::ReadOnly | QIODevice::Text);
    QString StyleSheet = QLatin1String(File.readAll());

    a.setStyleSheet(StyleSheet);@
    

    When I want to use this resource, I get an error: "QIODevice::read: device not open"

    In my cmakelists.txt, the relevant section is:

    @set (project_RESOURCES ScRes.qrc )

    QT5_WRAP_CPP (project_HEADERS_MOC ${project_HEADERS})
    QT5_WRAP_UI (project_FORMS_HEADERS ${project_FORMS})
    QT5_ADD_RESOURCES (project_RESOURCES_RCC ${project_RESOURCES})

    set_source_files_properties(${project_RESOURCES_RCC} PROPERTIES GENERATED ON)

    ADD_EXECUTABLE (Scanopus ${project_SOURCES} ${project_FORMS_HEADERS} ${project_HEADERS_MOC} ${project_RESOURCES})@

    The cmakelists.txt is also in the same folder with the .qrc and the main.cpp files.

    Does anyone have any suggestions on why my resource does not load correctly?

    Thank you in advance,
    András

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, welcome to devnet.

      You should check your return codes. You won't be able to read the file if QFile::open returns false.

      Anyway, with that resource file structure you should adjust your path like this:
      @QFile File(":/Resources/ScStyleSheet.qss");@

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fandras90
        wrote on last edited by
        #3

        Hi Chris,
        Thanks for your response. Actually, the other way doesn't work either. I get a "device not open" message. I have the qrc_ScRes.cpp generated but I cannot open the .qss from the resource. File.errorString() returns "Unknown error", and File.error() returns OpenError (0n5). Does this say something to you?

        Thanks
        András

        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