Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. QML plugins are not imported when using CMake and static Qt
QtWS25 Last Chance

QML plugins are not imported when using CMake and static Qt

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
3 Posts 3 Posters 1.8k 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.
  • E Offline
    E Offline
    Erulission
    wrote on last edited by
    #1

    Hello!

    Recently I have been struggling with CMake & static Qt build.
    Consider a very simple application written with QML:

    import QtQuick 2.14
    import QtQuick.Controls 2.14
    import QtQuick.Window 2.14
    
    Window {
      visible: true
      width: 640
      height: 480
      title: qsTr("Hello World")
    
      Button {
        anchors.centerIn: parent
        text: "Button :)"
      }
    }
    

    When I build this application using qmake everything works fine. I can run my app without any troubles, everything is packed inside executable. However, using CMake for the same project produces executable that not contain qml plugins (Error in runtime: QQmlApplicationEngine failed to load component qrc:/main.qml:1:1: module "QtQuick" plugin "qtquick2plugin" not found

    My CMake file:

    cmake_minimum_required(VERSION 3.5)
    
    project(cmake_sample LANGUAGES CXX)
    
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(BUILD_SHARED_LIBS OFF)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    
    find_package(Qt5 COMPONENTS Core Quick REQUIRED)
    
    add_executable(cmake_sample
        main.cpp
        qml.qrc
    )
    
    target_compile_definitions(cmake_sample
      PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
    target_link_libraries(cmake_sample
      PRIVATE Qt5::Core Qt5::Quick)
    

    To fix this I have to manually import & link all required QML plugins. While it solves the problem, it's very bulky on larger projects. I have the impression that these plugins should be automatically imported (others, like imageformats are ...)

    Question: Is it intended in CMake or it is a bug? If it is intended, is there any correct and elegant solution to properly configure CMake project against static Qt?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Cajus Pollmeier
      wrote on last edited by
      #2

      Had the same issue and got the hint that you can do:

      find_package(Qt5QmlImportScanner REQUIRED)
      qt5_import_qml_plugins(yourapp)
      
      1 Reply Last reply
      2
      • Q Offline
        Q Offline
        qtop
        wrote on last edited by
        #3

        This fixed it for me: https://doc.qt.io/qt-5/qtqml-cmake-qt5-import-qml-plugins.html

        I hope it helps.

        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