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. QT plugin interface inherits QObject
Forum Updated to NodeBB v4.3 + New Features

QT plugin interface inherits QObject

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 2.1k 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.
  • M Offline
    M Offline
    mgreenish
    wrote on 4 Jan 2018, 22:13 last edited by
    #1

    Can an interface class for a qt plugin (that extends the main application's functionality) inherit QObject?

    J 1 Reply Last reply 4 Jan 2018, 23:18
    0
    • M mgreenish
      4 Jan 2018, 22:13

      Can an interface class for a qt plugin (that extends the main application's functionality) inherit QObject?

      J Offline
      J Offline
      JonB
      wrote on 4 Jan 2018, 23:18 last edited by
      #2

      @mgreenish
      I keep poking my nose in where I know nothing. But posts like http://lists.qt-project.org/pipermail/interest/2014-May/012411.html seem to indicate not? They keep saying it must be "pure virtual".

      But I wouldn't listen to me, and you should await the experts....

      J 1 Reply Last reply 5 Jan 2018, 08:23
      0
      • J JonB
        4 Jan 2018, 23:18

        @mgreenish
        I keep poking my nose in where I know nothing. But posts like http://lists.qt-project.org/pipermail/interest/2014-May/012411.html seem to indicate not? They keep saying it must be "pure virtual".

        But I wouldn't listen to me, and you should await the experts....

        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 5 Jan 2018, 08:23 last edited by
        #3

        @JonB said in QT plugin interface inherits QObject:

        @mgreenish
        I keep poking my nose in where I know nothing. But posts like http://lists.qt-project.org/pipermail/interest/2014-May/012411.html seem to indicate not? They keep saying it must be "pure virtual".

        But I wouldn't listen to me, and you should await the experts....

        You don't need to be an expert to find information ;)

        @JonB's interpretation is correct. The interface class cannot inherit QObject, but the implementation can.

        See the example at http://doc.qt.io/qt-5/plugins-howto.html -- FilterInterface cannot inherit QObject, but ExtraFiltersPlugin inherits both FilterInterface and QObject.

        @mgreenish said in QT plugin interface inherits QObject:

        Can an interface class for a qt plugin (that extends the main application's functionality) inherit QObject?

        What is your end-goal? Why would you like the interface class itself to inherit QObject?

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        1
        • B Offline
          B Offline
          Buckwheat
          wrote on 8 Jan 2018, 19:38 last edited by
          #4

          @mgreenish
          Hi and Welcome!

          I agree with @JonB... what is your end goal. By definition, interfaces define access points to provide functionality and should NOT and should NEVER derive from QObject. Ideally, your interface should be pure virtual and contain absolutely no code or data.

          Once you have established an interface, your derived implementation can also be derived from QObject (and should) for the plugin framework to work.

          Qt has very nice documentation about the plugin framework and a simple example. Please refer to it for information and cut-n-paste code!

          Dave Fileccia

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mgreenish
            wrote on 9 Jan 2018, 12:20 last edited by
            #5

            Thank you for the feedback. I did search before adding my post but as JonB, I only found posts that seemed to 'indicate' not. Thanks to JKSH & Buckwheat for clarifying.

            I wasn't sure how to use the signals & slots mechanism to trigger events in my main application from my plugin. But given your feedback, I figured it out:

                QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
                QObject *plugin = pluginLoader.instance();
                if( plugin ) {
                    reactionsserverInterface = qobject_cast<ReactionsServerInterface *>(plugin);
                    if( reactionsserverInterface ) {
                        reactionsserverInterface->setParentCW(this);
                        connect( this, SIGNAL(effectsSent(QJsonDocument)), plugin, SLOT(saveReactionFile(QJsonDocument)) );
                        connect( plugin, SIGNAL(reactionFileNameUpdated(QString)), this, SLOT(updateReactionFileName(QString) ) );
                        return true;
                    }
                }
            

            I was trying to tie back to reactionsserverInterface and that didn't work, but tying back to plugin worked.

            Thanks!

            1 Reply Last reply
            0

            1/5

            4 Jan 2018, 22:13

            • Login

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