Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Accessing the Plugin metadata starting from a QObject*
Forum Update on Monday, May 27th 2025

Accessing the Plugin metadata starting from a QObject*

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 907 Views
  • 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.
  • L Offline
    L Offline
    Lolo67
    wrote on last edited by
    #1

    Supposing I maintain a list of QObject* that was retrieved via QPluginLoader::instance() and via QPluginLoader::staticPlugins().

    I am looking for a simple way to retrieve the plugin metaData starting from the QObject*

    jsulmJ 1 Reply Last reply
    0
    • L Lolo67

      Supposing I maintain a list of QObject* that was retrieved via QPluginLoader::instance() and via QPluginLoader::staticPlugins().

      I am looking for a simple way to retrieve the plugin metaData starting from the QObject*

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Lolo67 Check the documentation: http://doc.qt.io/qt-5/qpluginloader.html#instance
      "The component object is a QObject. Use qobject_cast() to access interfaces you are interested in."

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Lolo67
        wrote on last edited by
        #3

        I don't see how qobject_cast() could bring me to the metaData defined via Q_PLUGIN_METADATA.

        jsulmJ 1 Reply Last reply
        1
        • L Lolo67

          I don't see how qobject_cast() could bring me to the metaData defined via Q_PLUGIN_METADATA.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Lolo67 What about http://doc.qt.io/qt-5/qpluginloader.html#metaData and http://doc.qt.io/qt-5/qstaticplugin.html#metaData?
          It's all in the documentation...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • S Offline
            S Offline
            StefanBruens
            wrote on last edited by
            #5

            It is not in the documentation.

            metaData() is a method of the QPluginLoader, not the QObject instance, as returned by QPluginLoader::instance(). There is no way, at least not documented from e.g. (QObject*)(this) to the metadata.

            E.g.

            QPluginLoader loader("my/plugins/foo.so");
            // metadata is available here:
            auto meta = loader.metaData();
            auto foo = loader.instance();
            auto bar = qobject_cast<BarInterface>(foo);
            
            ...
            Class Foo : public BarInterface
            {
                Foo::Foo() {
                   // this->metaData() - not accessible here
                }
            };
            
            

            Unless the metaData is passed back from the loader to the plugin instance, it seems to be unavailable.

            kshegunovK 1 Reply Last reply
            0
            • S StefanBruens

              It is not in the documentation.

              metaData() is a method of the QPluginLoader, not the QObject instance, as returned by QPluginLoader::instance(). There is no way, at least not documented from e.g. (QObject*)(this) to the metadata.

              E.g.

              QPluginLoader loader("my/plugins/foo.so");
              // metadata is available here:
              auto meta = loader.metaData();
              auto foo = loader.instance();
              auto bar = qobject_cast<BarInterface>(foo);
              
              ...
              Class Foo : public BarInterface
              {
                  Foo::Foo() {
                     // this->metaData() - not accessible here
                  }
              };
              
              

              Unless the metaData is passed back from the loader to the plugin instance, it seems to be unavailable.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @StefanBruens said in Accessing the Plugin metadata starting from a QObject*:

              Unless the metaData is passed back from the loader to the plugin instance, it seems to be unavailable.

              The meta data is not available through the QObject, get it from the loader if you need it. Strictly speaking Q_PLUGIN_METADATA is a moc artifact that facilitates the plugin loading and you shouldn't really need it to begin with, while on the other hand the QObject you get isn't a plugin it's the entry point for the plugin.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              2

              • Login

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