QML Plugin QQmlComponent: Component is not ready
-
Hello,
I'm just starting with QML so bare with me.
I have a client qml application and a qml plugin.
Client Cmakeproject(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 CmakeProject(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_HMyPlugin.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.0toapplication.qmlI 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.
-
Hello,
I'm just starting with QML so bare with me.
I have a client qml application and a qml plugin.
Client Cmakeproject(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 CmakeProject(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_HMyPlugin.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.0toapplication.qmlI 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.
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/importsandQQmlEngine engine; engine.addImportPath(":/myplugin/imports"); -
R Redman has marked this topic as solved on