Is there any way to obtain information from qml plugin library in the application?

  • Is it possible to load QML plugin from C++, say, from QPluginLoader to work with it's functions? In my project, I have a qml plugin with a version information in it and I want to read it from C++.


    main() {
        // ...
        QQmlApplicationEngine engine;
        if (parser.isSet(verionsOption)) {
            QSharedPointer<QQmlExtensionPlugin> myPlugin = // load plugin
            std::cout << "Version of plugin: " << myPlugin->version() << std::endl;
        return app.exec();

    As version, I need to obtain another data. I think it is possible to load it as simple library (QPluginLoader or something else) but I don't know how.

  • Lifetime Qt Champion


    IIRC, the QML plugins are standard Qt plugin so you can load them like standard plugin. If you have the version in the plugin metadata you can even avoid loading the plugin.

    Hope it helps

  • @SGaist Unfortutanely I am unable to load Qml plugin by using QLibrary and QPluginLoader classes.

    I don't even understand how to load it properly since it is not just a QPlugin but QML Plugin: it's path differ from just qt plugin. I try to load like this:

    qDebug() << "LIBRARY PATHS: " << QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath);
    QLibrary qmlPlugin("/Users/user/Qt/5.4/clang_64/qml/fx/qllauncher/libfxqllauncher.dylib");
    qDebug() << "ERROR: " << qmlPlugin.errorString();

    It always says "Unknown error". Instead of just plain file name I tried really everything:

    1. libfxqllauncher.dylib
    2. libfxqllauncher
    3. fxqllauncher
    4. /Users/user/Qt/5.4/clang_64/qml/fx/qllauncher/libfxqllauncher.dylib
    5. /Users/user/Qt/5.4/clang_64/qml/fx/qllauncher/libfxqllauncher
    6. /Users/user/Qt/5.4/clang_64/qml/fx/qllauncher/fxqllauncher
    7. Previous 6 with "_debug" suffix.

    Also I tried to launch my application in the debug/release mode but that did not help.

    My qml plugin works fine for a year. Here is it's header file:

    #include <QQmlExtensionPlugin>
    class FXQLLauncherPlugin : public QQmlExtensionPlugin
        Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
        void registerTypes(const char *uri);
        void initializeEngine(QQmlEngine *engine, const char *uri);

    Implementation is really boring and default so I will not provide .cpp code of this file (not necessary).

    Can you please give me working code example?

    UPD: okay. Qt5 documentations sucks or my english is bad. I needed to use "QPluginLoader::load()" method explicitly and it works now. Why did not I use it before?
    Because Qt documentation (in my opinion) says that it will load library automatically after constructing QPluginLoader object with filename:

    Constructs a plugin loader with the given parent that will load the plugin specified by fileName.

Log in to reply

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