How to surpress QML plugins to be built statically?



  • I've built Qt 5.3.1 statically, and make a Quick Application based on Quick Application Template generated by Qt Creator.
    When I want to run it standalone, it doesn't show anything though application runs in background. Turning on console and it shows:

    @QQmlApplicationEngine failed to load component
    qrc:///qml/main.qml:2 module "QtQuick.Controls" is not installed
    qrc:///qml/main.qml:1 module "QtQuick" is not installed
    qrc:///qml/main.qml:2 module "QtQuick.Controls" is not installed
    qrc:///qml/main.qml:1 module "QtQuick" is not installed@

    Then after discovery, I know that to resolve this problem, I have to put application binary into $$QTSDK/qml directory.

    My question is how to supress all QML plugins to be built statically so as to remove the dependency of "qml" directory and the application binary is fully "standalone"? all other QML files made myself have been packed into qrc file and compiled via rcc, that is not the problem.



  • Currently my problem is somewhat the same as the following bug report:
    https://bugreports.qt-project.org/browse/QTBUG-39462
    Now, I have to work around it by explicitly setting code for it.

    @#include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QtPlugin>
    #include <QtQml>

    #if defined(QT_STATIC) && !defined(Q_OS_MAC) && !defined(QT_NAMESPACE)
    Q_IMPORT_PLUGIN(QtQuick2Plugin)
    Q_IMPORT_PLUGIN(QtQuickControlsPlugin)
    Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin)
    Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)
    #endif

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

    ……

    QQmlApplicationEngine engine;
    
    // 在静态编译下一个通融的解决方法是显式地注册QML类
    

    #if defined(QT_STATIC) && !defined(Q_OS_MAC) && !defined(QT_NAMESPACE)
    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.2");

    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuick2Plugin().instance())       ->initializeEngine( &engine, "QtQuick");
    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuickControlsPlugin().instance())->initializeEngine( &engine, "QtQuick.Controls");
    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuickLayoutsPlugin().instance()) ->initializeEngine( &engine, "QtQuick.Layouts");
    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuickLayoutsPlugin().instance()) ->initializeEngine( &engine, "QtQuick.Layouts");
    qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuick2WindowPlugin().instance()) ->initializeEngine( &engine, "QtQuick.Window.2");
    

    #endif

    ……

    return app.exec( );
    }
    @




Log in to reply
 

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