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. qt_add_resources not adding resources

qt_add_resources not adding resources

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 380 Views 3 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.
  • l3u_L Offline
    l3u_L Offline
    l3u_
    wrote on last edited by l3u_
    #1

    Hi all,

    I hope someone with real insight of all that can explain this to me.

    I recently got a merge request for KGeoTag fixing a startup crash. The problem was that KGeoTag uses KDE's KXmlGui classes, and it needs a definition file to be present (kgeotagui.rc in this case), otherwise, it will crash when starting. Said file was bundled via Qt's resource system.

    I recently dropped Qt5/KF5 support and reworked my CMakeLists.txt sources management a bit: Instead of having multiple variables containing all source files, I now first define a target like that:

    add_executable(kgeotag)
    

    and then I add the sources directory containing all source files and an own CMakeLists.txt file like that:

    add_subdirectory(src)
    

    Inside src/, the sources definition looks like this:

        target_sources(kgeotag PRIVATE
            ${CMAKE_CURRENT_SOURCE_DIR}/AutomaticMatchingWidget.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/AutomaticMatchingWidget.h
            ${CMAKE_CURRENT_SOURCE_DIR}/BookmarksList.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/BookmarksList.h
            ...
        )
    

    However, adding said resource file seems not to work anymore using this setup. Until now, I used

    qt_add_resources(kgeotag ${CMAKE_SOURCE_DIR}/kgeotag.qrc)
    

    With kgeotag.qrc being:

    <RCC version="1.0">
        <qresource prefix="/kxmlgui5/kgeotag">
            <file>kgeotagui.rc</file>
        </qresource>
    </RCC>
    

    But kgeotagui.rc is actually not included, no matter where I put the macro. And the program crashes on startup, due to the file being not present.

    However, if I don't use qt_add_resources but add kgeotag.qrc to the sources list like that:

    target_sources(kgeotag PRIVATE
        ${CMAKE_SOURCE_DIR}/kgeotag.qrc
    )
    

    in the top-level CMakeLists.txt (cf. the corresponding patch), the rc file is added like it should and the program's startup runs as expected.

    So: Why does qt_add_resources not work anymore here?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From a quick look at the qt_add_resources documentation:

      set(sources main.cpp)
      qt_add_resources(sources example.qrc)
      qt_add_executable(myapp ${sources})
      

      It seems that qt_add_resources, in the context of a qrc file, should be called with a variable containing the list of files for your executable.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      l3u_L 1 Reply Last reply
      1
      • M Offline
        M Offline
        MalcolmSequeira
        wrote on last edited by MalcolmSequeira
        #3

        perhaps you could add this to the cmake file?

        set(CMAKE_AUTORCC ON)
        
        JKSHJ 1 Reply Last reply
        0
        • B Offline
          B Offline
          Bonnie
          wrote on last edited by
          #4

          As @SGaist said. Are you sure your qt_add_resources code above ever worked? I tried qt_add_resources(target res.qrc) in a Qt5 cmake project and it doesn't work.

          1 Reply Last reply
          1
          • M MalcolmSequeira

            perhaps you could add this to the cmake file?

            set(CMAKE_AUTORCC ON)
            
            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @l3u_ said in qt_add_resources not adding resources:

            qt_add_resources(kgeotag ${CMAKE_SOURCE_DIR}/kgeotag.qrc)
            

            With kgeotag.qrc being:

            <RCC version="1.0">
                <qresource prefix="/kxmlgui5/kgeotag">
                    <file>kgeotagui.rc</file>
                </qresource>
            </RCC>
            

            I believe what you want is (replace "MyResources" with whatever name you like):

            qt_add_resources(kgeotag "MyResources"
                PREFIX "/kxmlgui5/kgeotag"
                FILES ${CMAKE_SOURCE_DIR}/kgeotagui.rc
            )
            

            The *.qrc file is redundant.

            Anyway, when troubleshooting resource issues, try the following snippet:

            QDirIterator qrc(":", QDirIterator::Subdirectories);
            while(qrc.hasNext())
                qDebug() << qrc.next();
            

            @MalcolmSequeira said in qt_add_resources not adding resources:

            perhaps you could add this to the cmake file?

            set(CMAKE_AUTORCC ON)
            

            The target-based qt_add_resources() replaces CMAKE_AUTORCC. CMAKE_AUTORCC should not be used anymore: https://bugreports.qt.io/browse/QTBUG-87643

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              From a quick look at the qt_add_resources documentation:

              set(sources main.cpp)
              qt_add_resources(sources example.qrc)
              qt_add_executable(myapp ${sources})
              

              It seems that qt_add_resources, in the context of a qrc file, should be called with a variable containing the list of files for your executable.

              l3u_L Offline
              l3u_L Offline
              l3u_
              wrote on last edited by
              #6

              @SGaist said in qt_add_resources not adding resources:

              Hi,

              From a quick look at the qt_add_resources documentation:

              set(sources main.cpp)
              qt_add_resources(sources example.qrc)
              qt_add_executable(myapp ${sources})
              

              It seems that qt_add_resources, in the context of a qrc file, should be called with a variable containing the list of files for your executable.

              So the core issue is that I can define my sources via target_sources, but this won't work with qt_add_resources, as this one only works with a (classic) list of files, and not with target_sources?

              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