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. QML Plugin QQmlComponent: Component is not ready
Qt 6.11 is out! See what's new in the release blog

QML Plugin QQmlComponent: Component is not ready

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 385 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
    Redman
    wrote on last edited by Redman
    #1

    Hello,

    I'm just starting with QML so bare with me.

    I have a client qml application and a qml plugin.

    Client Cmake

    project(Client)
    qt_add_executable(${PROJECT_NAME}
            src/main.cpp
    )
    qt_standard_project_setup(REQUIRES 6.5)
    
    qt_add_qml_module(${PROJECT_NAME}
        URI ${PROJECT_NAME}
        QML_FILES
            src/qml/application.qml
    )
    
    set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
    
    # Link against libraries
    target_link_libraries(${PROJECT_NAME} PRIVATE
        Qt${QT_MAJOR_VERSION}::RemoteObjects
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_MAJOR_VERSION}::Quick
        MyPlugin <-- is this actually needed?
    )
    

    Client main.cpp

    #include <QtQuick>
    int
    main(int argc, char* argv[]) {
       // Init Gui Application
       QGuiApplication app(argc, argv);
       QQmlEngine engine;
       QQmlComponent component(&engine,
           QUrl("qrc:/qt/qml/Client/src/qml/application.qml"));
       QObject* appWindow = component.create();
    

    application.qml (example application.qml from docs)

    //import related modules
    import QtQuick 2.15
    import QtQuick.Controls
    
    //window containing the application
    ApplicationWindow {
    
        visible: true
    
        //title of the application
        title: qsTr("Hello World")
        width: 640
        height: 480
    
        //menu containing two menu items
        menuBar: MenuBar {
            Menu {
                title: qsTr("File")
                MenuItem {
                    text: qsTr("&Open")
                    onTriggered: console.log("Open action triggered");
                }
                MenuItem {
                    text: qsTr("Exit")
                    onTriggered: Qt.quit();
                }
            }
        }
    
        //Content Area
    
        //a button in the middle of the content area
        Button {
            text: qsTr("Hello World")
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
        }
    }
    
    

    This part works fine.

    Now to my plugin
    MyPlugin Cmake

    Project(MyPlugin)
    
    qt_add_qml_module(${PROJECT_NAME}
        URI MyPlugin
        VERSION 1.0
        SOURCES
            src/MyPlugin.h
        QML_FILES
            src/qml/MyPlugin.qml
    
    )
    
    target_sources(${PROJECT_NAME}
      PRIVATE
        src/qml/MyPlugin.qml
    )
    qt_standard_project_setup()
    
    set_target_properties(${PROJECT_NAME} PROPERTIES
        LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/../../../../../plugins"
    )
    
    target_link_libraries(${PROJECT_NAME} PRIVATE
        Qt${QT_MAJOR_VERSION}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_MAJOR_VERSION}::Quick
    )
    

    MyPlugin.h

    #ifndef MYPLUGIN_H
    #define MYPLUGIN_H
    
    #include <QQmlExtensionPlugin>
    
    class MyPlugin : public QQmlExtensionPlugin {
       Q_OBJECT
       Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
     public:
       void
       registerTypes(const char* uri) {}
    };
    
    #endif MYPLUGIN_H
    

    MyPlugin.qml (just some random code I copied)

    import QtQuick 2.15
    import QtQuick.Controls
    
    Item {
        //a button in the middle of the content area
        Button {
            text: qsTr("Hello World")
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
        }
    }
    

    Now, when I add the import MyPlugin 1.0 to application.qml I get
    QQmlComponent: Component is not ready. If I take it out, there is no error and the application serves as intended.

    Ctrl+mouseleft jumps to the correct qml. Dont know if it's because qtcreator is smart or its looking that up in the QML_IMPORT_PATH which indicates at least some succes.

    R 1 Reply Last reply
    0
    • R Redman

      Hello,

      I'm just starting with QML so bare with me.

      I have a client qml application and a qml plugin.

      Client Cmake

      project(Client)
      qt_add_executable(${PROJECT_NAME}
              src/main.cpp
      )
      qt_standard_project_setup(REQUIRES 6.5)
      
      qt_add_qml_module(${PROJECT_NAME}
          URI ${PROJECT_NAME}
          QML_FILES
              src/qml/application.qml
      )
      
      set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
      
      # Link against libraries
      target_link_libraries(${PROJECT_NAME} PRIVATE
          Qt${QT_MAJOR_VERSION}::RemoteObjects
          Qt${QT_MAJOR_VERSION}::Gui
          Qt${QT_MAJOR_VERSION}::Quick
          MyPlugin <-- is this actually needed?
      )
      

      Client main.cpp

      #include <QtQuick>
      int
      main(int argc, char* argv[]) {
         // Init Gui Application
         QGuiApplication app(argc, argv);
         QQmlEngine engine;
         QQmlComponent component(&engine,
             QUrl("qrc:/qt/qml/Client/src/qml/application.qml"));
         QObject* appWindow = component.create();
      

      application.qml (example application.qml from docs)

      //import related modules
      import QtQuick 2.15
      import QtQuick.Controls
      
      //window containing the application
      ApplicationWindow {
      
          visible: true
      
          //title of the application
          title: qsTr("Hello World")
          width: 640
          height: 480
      
          //menu containing two menu items
          menuBar: MenuBar {
              Menu {
                  title: qsTr("File")
                  MenuItem {
                      text: qsTr("&Open")
                      onTriggered: console.log("Open action triggered");
                  }
                  MenuItem {
                      text: qsTr("Exit")
                      onTriggered: Qt.quit();
                  }
              }
          }
      
          //Content Area
      
          //a button in the middle of the content area
          Button {
              text: qsTr("Hello World")
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.verticalCenter: parent.verticalCenter
          }
      }
      
      

      This part works fine.

      Now to my plugin
      MyPlugin Cmake

      Project(MyPlugin)
      
      qt_add_qml_module(${PROJECT_NAME}
          URI MyPlugin
          VERSION 1.0
          SOURCES
              src/MyPlugin.h
          QML_FILES
              src/qml/MyPlugin.qml
      
      )
      
      target_sources(${PROJECT_NAME}
        PRIVATE
          src/qml/MyPlugin.qml
      )
      qt_standard_project_setup()
      
      set_target_properties(${PROJECT_NAME} PROPERTIES
          LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/../../../../../plugins"
      )
      
      target_link_libraries(${PROJECT_NAME} PRIVATE
          Qt${QT_MAJOR_VERSION}::Core
          Qt${QT_MAJOR_VERSION}::Gui
          Qt${QT_MAJOR_VERSION}::Quick
      )
      

      MyPlugin.h

      #ifndef MYPLUGIN_H
      #define MYPLUGIN_H
      
      #include <QQmlExtensionPlugin>
      
      class MyPlugin : public QQmlExtensionPlugin {
         Q_OBJECT
         Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
       public:
         void
         registerTypes(const char* uri) {}
      };
      
      #endif MYPLUGIN_H
      

      MyPlugin.qml (just some random code I copied)

      import QtQuick 2.15
      import QtQuick.Controls
      
      Item {
          //a button in the middle of the content area
          Button {
              text: qsTr("Hello World")
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.verticalCenter: parent.verticalCenter
          }
      }
      

      Now, when I add the import MyPlugin 1.0 to application.qml I get
      QQmlComponent: Component is not ready. If I take it out, there is no error and the application serves as intended.

      Ctrl+mouseleft jumps to the correct qml. Dont know if it's because qtcreator is smart or its looking that up in the QML_IMPORT_PATH which indicates at least some succes.

      R Offline
      R Offline
      Redman
      wrote on last edited by Redman
      #2

      @Redman

      https://www.youtube.com/watch?v=5YoEjIbzBA0 followed the steps in this video. Now it works. Missing was the qt_add_library(${PROJECT_NAME} STATIC), RESOURCE_PREFIX myplugin/imports and QQmlEngine engine; engine.addImportPath(":/myplugin/imports");

      1 Reply Last reply
      0
      • R Redman has marked this topic as solved on

      • Login

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