Static plugins for qml app



  • Hello all.
    I want to include static plugins in my qml project. As i understand i need to use <QtPlugin> and <QQmlExtensionPlugin>.
    When I create QtQuick2 project without QtQuick.Controls it works fine with static plugins:
    qml:
    @
    import QtQuick 2.2
    //import QtQuick.Controls 1.1

    Rectangle{
    width: 200
    height: 200
    color: "LightGreen"
    }
    @
    cpp:
    @
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>

    #include <QQuickView>
    #include <QtPlugin>
    #include <QQmlEngine>

    #include <QQmlExtensionPlugin>
    Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
    Q_IMPORT_PLUGIN(QtQuick2Plugin)

    int main(int argc, char argv[])
    {
    QGuiApplication app(argc, argv);
    qobject_cast<QQmlExtensionPlugin
    >(qt_static_plugin_QtQuick2Plugin().instance())->registerTypes("QtQuick");

    QQuickView viewer;
    viewer.engine()->setImportPathList(QStringList());
    viewer.setSource(QUrl(QStringLiteral("qrc:///main.qml")));
    viewer.show();
    
    return app.exec&#40;&#41;;
    

    }
    @

    But when i try to use QtQuick.Controls...
    qml:
    @
    import QtQuick 2.2
    import QtQuick.Controls 1.1

    ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Exit2")
                onTriggered: Qt.quit();
            }
        }
    }
    
    Text {
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }
    

    }
    @
    cpp:
    @
    #include <QApplication>
    #include <QQmlApplicationEngine>

    #include <QtPlugin>
    #include <QQmlExtensionPlugin>

    Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
    Q_IMPORT_PLUGIN(QtQuick2Plugin)
    Q_IMPORT_PLUGIN(QtQuickControlsPlugin)
    Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin)
    Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)

    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);

    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuick2Plugin().instance())->registerTypes("QtQuick");
    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuickControlsPlugin().instance())->registerTypes("QtQuick.Controls");
    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuickControlsPlugin().instance())->registerTypes("QtQuick.Controls.Private");
    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuickControlsPlugin().instance())->registerTypes("QtQuick.Controls.Styles");
    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuickLayoutsPlugin().instance())->registerTypes("QtQuick.Layouts");
    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuick2WindowPlugin().instance())->registerTypes("QtQuick.Window");
    
    QQmlApplicationEngine engine;
    engine.setImportPathList(QStringList());
    engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
    
    return app.exec(&#41;;
    

    }
    @

    In this case i get error: "ContentItem is not a type". I know that ContentItem is qml type from QtQuick.Controls.Private. And i assume that i did incorrect type registration for this namespace.

    How can i solve this problem?



  • still no answers...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.