Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. How to access immediate resources imported by qt6_add_resources?
Forum Updated to NodeBB v4.3 + New Features

How to access immediate resources imported by qt6_add_resources?

Scheduled Pinned Locked Moved Solved Qt 6
3 Posts 2 Posters 483 Views 2 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.
  • Z Offline
    Z Offline
    ZXfkSIE
    wrote on last edited by
    #1

    I've written these codes in CMakeLists.txt:

    set(TP_IMAGE_FILES
        ${PROJECT_SOURCE_DIR}/image/icon_Exit.svg
        )
    
    # TP_ui is the target containing UI codes
    qt6_add_resources(TP_ui "image"
        PREFIX "/image"
        FILES ${TP_IMAGE_FILES}
        )
    

    However, in cpp files, the file path ":/image/icon_Exit.svg" doesn't exist.

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

      Hi,

      You can use QDir to go though the content of your resources.

      My guess is the the paths you are using to list the files for your resources is appended to your prefix.

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

      1 Reply Last reply
      2
      • Z Offline
        Z Offline
        ZXfkSIE
        wrote on last edited by
        #3

        OK I just checked the directories and files output by the code:

            QDirIterator it(":", QDirIterator::Subdirectories);
            while (it.hasNext()) {
                qDebug() << it.next();
            }
        

        and the file is stored as absolute path.

        I changed the related CMake code to

        qt6_add_resources(TP_ui "image"
            PREFIX "/image"
            BASE "${PROJECT_SOURCE_DIR}/image"
            FILES ${TP_IMAGE_FILES}
            )
        

        and solved the problem.

        1 Reply Last reply
        3

        • Login

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