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. Is there any way to obtain information from qml plugin library in the application?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
qmllibraryplugin
3 Posts 2 Posters 1.6k Views 2 Watching
  • 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.
  • V Offline
    V Offline
    vityafx4
    wrote on last edited by
    #1

    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++.

    Example:

    main() {
        // ...
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:///ui/views/mainwindow.qml")));
    
        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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        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

        V Offline
        V Offline
        vityafx4
        wrote on last edited by vityafx4
        #3

        @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:

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

        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.
        
        1 Reply Last reply
        0

        • Login

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