Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Can I create a static library from QML and use that with my executable?

Can I create a static library from QML and use that with my executable?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlcmakeresources
3 Posts 2 Posters 2.3k Views
  • 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.
  • R Offline
    R Offline
    rhvonlehe
    wrote on 17 Sept 2019, 18:34 last edited by rhvonlehe
    #1

    I have a CMake Qt project. It used to be qmake, but it's being slowly converted to CMake. I am trying to put some commonly-used QML into a static library and then allowing applications to link against this static library. Compiling and linking works, but I get run-time errors saying e.g. module "BCControls" is not installed.

    The CMake for the static library is:

    add_library(BCControls STATIC)
    
    qt5_add_resources(RESOURCES bccontrols.qrc)
    
    target_sources(BCControls
        PRIVATE
        ${RESOURCES}
        )
    

    The application's CMake is:

    add_executable(PerMain)
    
    qt5_add_resources(RESOURCES qml.qrc)
    
    target_include_directories(PerMain PRIVATE .)
    
    target_sources(PerMain
        PRIVATE
        ${RESOURCES}
        main.cpp
        PerMainApp.cpp
        )
    
    target_link_libraries(PerMain
        PRIVATE
        Qt5::Core
        PrinterIF
        BQIF
        Properties
        AppData
        CommonBaseErrorDetectors
        BCControls
        )
    

    Everything works fine if I put the bccontrols.qrc in the PerMain/CMakeLists.txt like this:

    add_executable(PerMain)
    
    qt5_add_resources(RESOURCES
        qml.qrc
        ../../QtCommon/BCControls/bccontrols.qrc
        )
    
    target_include_directories(PerMain PRIVATE .)
    
    target_sources(PerMain
        PRIVATE
        ${RESOURCES}
        main.cpp
        PerMainApp.cpp
        )
    
    target_link_libraries(PerMain
        PRIVATE
        Qt5::Core
        PrinterIF
        BQIF
        Properties
        AppData
        CommonBaseErrorDetectors
    #    BCControls
        )
    

    Is it possible to use a static library in the way I'm trying to use it? If so, what am I missing?

    Thanks!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 18 Sept 2019, 05:44 last edited by
      #2

      When you are adding resources to a library, you need to init them manually.See the docs: https://doc.qt.io/qt-5/resources.html#using-resources-in-a-library

      (Z(:^

      R 1 Reply Last reply 18 Sept 2019, 14:12
      2
      • S sierdzio
        18 Sept 2019, 05:44

        When you are adding resources to a library, you need to init them manually.See the docs: https://doc.qt.io/qt-5/resources.html#using-resources-in-a-library

        R Offline
        R Offline
        rhvonlehe
        wrote on 18 Sept 2019, 14:12 last edited by
        #3

        @sierdzio Thank you.

        1 Reply Last reply
        0

        1/3

        17 Sept 2019, 18:34

        • Login

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