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. Add resource file (*.qrc) to static library. How?
Forum Updated to NodeBB v4.3 + New Features

Add resource file (*.qrc) to static library. How?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 94 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.
  • B Offline
    B Offline
    bogong
    wrote last edited by
    #1

    Hello all!

    Trying to add QML files to static library (need to create universal library within QML). All is working when directly adding QML with 'qt_add_qml_module'. Something like this:

    qt_add_qml_module(${A_NAME_TARGET}
    	URI "Library_v1"
    	QML_FILES
    		"ATestQML.qml"
    )
    

    How to add *.qrc files to library and how to use it in the main project? When adding *.qrc file to the library with 'qt_add_qml_module' return error:

    qt_add_qml_module(${A_NAME_TARGET}
    	URI "Library_v1"
    	RESOURCES
    		TestResources.qrc
    )
    

    error in the main project:

    QQmlApplicationEngine failed to load component
    qrc:/qt/qml/Application_v1/Main.qml:12:2: ATestQML is not a type
    
    JKSHJ 1 Reply Last reply
    0
    • I Offline
      I Offline
      IgKh
      wrote last edited by
      #2

      I don't know anything specific about QML modules, but in general - if you want to load a resource file from a static library, you need explicitly load it by adding the Q_INIT_RESOURCE macro somewhere in your main application target. See the docs: https://doc.qt.io/qt-6/qtresource-qtcore-proxy.html#Q_INIT_RESOURCE

      1 Reply Last reply
      0
      • B bogong

        Hello all!

        Trying to add QML files to static library (need to create universal library within QML). All is working when directly adding QML with 'qt_add_qml_module'. Something like this:

        qt_add_qml_module(${A_NAME_TARGET}
        	URI "Library_v1"
        	QML_FILES
        		"ATestQML.qml"
        )
        

        How to add *.qrc files to library and how to use it in the main project? When adding *.qrc file to the library with 'qt_add_qml_module' return error:

        qt_add_qml_module(${A_NAME_TARGET}
        	URI "Library_v1"
        	RESOURCES
        		TestResources.qrc
        )
        

        error in the main project:

        QQmlApplicationEngine failed to load component
        qrc:/qt/qml/Application_v1/Main.qml:12:2: ATestQML is not a type
        
        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote last edited by
        #3

        @bogong said in Add resource file (*.qrc) to static library. How?:

        How to add *.qrc files to library and how to use it in the main project?

        You would use qt_add_resources() for *.qrc files: https://doc.qt.io/qt-6/qt-add-resources.html

        However, if your *.qml files are inside a *.qrc then you won't get the full benefits of qt_add_qml_module() (such as optimization via the Qt Quick Compiler: https://www.qt.io/blog/the-numbers-performance-benefits-of-the-new-qt-quick-compiler).

        It is better to move all your files out of the *.qrc, and directly into the qt_add_qml_module():

        qt_add_qml_module(${A_NAME_TARGET}
        	URI Library_v1
        	QML_FILES
        		ATestQML.qml
        		BTestQML.qml
        	RESOURCES
        		myimage.png
        		myotherimage.png
        )
        

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

        1 Reply Last reply
        2

        • Login

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