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. Load the QML plugin automatically when application starts
Forum Updated to NodeBB v4.3 + New Features

Load the QML plugin automatically when application starts

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 289 Views 1 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #1

    Mac Qt 6.4

    Created the plugin using qt_add_qml_module. I have set QML_IMPORT_PATH = /Users/dheeru/libs.
    This fine.
    I would like the plugin in /Users/dheeru/libs/com/pthinks/libMyModulePlugin.dylib(Mac) to be automatically loaded.
    Is there any environment variable to set such that above library is loaded by QmlApplication Engine ?

    I don't want write a code in main.cpp to load the plugin using QPluginLoader.

    Is this possible ?

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      The plugin needs to be specified in the qmldir file.
      Here is a small example of how it works.
      Plumbing with QPluginLoader in main.cpp is not necessary.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      1
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by dheerendra
        #3

        Thank you @Axel-Spoerl. QML file(MyPthinkSMain.qml) to load is present in the plugin itself. Code snippet

            QPluginLoader 
            loader("/Users/dheeru/libs/India/Bengaluruu/PthinkS/QtExperts/libPthinkSUtilplugin.dylib");
            loader.load();
            const QUrl urlu"qrc:/India/Bengaluruu/PthinkS/QtExperts/MyPthinkSMain.qml"_qs);
            engine.load(url);
        

        The file qrc:/India/Bengaluruu/PthinkS/QtExperts/MyPthinkSMain.qml comes from the plugin libPthinkSUtilplugin.dylib itself. If I comment loader.load(), application does not show up window.

        As I understand plugin will be loaded once engine see the import statement in qml. Hope this is what you are describing. In my use case qml file itself comes from the plugin built using qt_add_qml_module.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        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