Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Global function access to all plugins
Qt 6.11 is out! See what's new in the release blog

Global function access to all plugins

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 5 Posters 6.2k 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.
  • SGaistS SGaist

    You should rather have an interface on your plugins that allows to configure them as needed rather than relying on an arbitrary order from some external source and your plugins having to know stuff they should not have to care for.

    L Offline
    L Offline
    Luckless
    wrote on last edited by
    #11

    @SGaist I dont understand how will I be able to access other plugin objects using such interface.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Luckless
      wrote on last edited by Luckless
      #12

      Currently I have used the following work around:
      1)Load all the plugins in main.cpp.
      2)Use the instance() function to get the base QObject instance of each plugin. Register these objects with an object name.
      3)Since qApp is a global pointer to QApplication instance, make all QObjects a child of qApp.
      4)use qApp pointer in all plugins to get any plugin instance i need, using findChildren().
      5)I use an interface file to cast the QObject into a type which the base class of the plugin inherits from and then I am able to use all funtions from the interface, whose definition are on that plugin.
      6)Also in order to take care of Plugin loading readiness. I have made a signal, which I call at the end of main.cpp, after all plugins have been loaded and connected to slot of all plugins defined in interface. So, all actions that require other plugins to be ready are performed in this slot of each plugin

      This works for me but I was looking for a neater alternative. Alternate to using qApp, I came up with this idea about a global class / pointer / function /variable.
      What is your comment on this @SGaist ?

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

        That you have a design issue.

        If you need your plugins to know a lot of stuff about other plugins then clearly there's something wrong going on.

        Are you sure that you need plugins at all ?

        The role of a plugin is to extend a functionality and if it's not there then the extension is simply not available. Here you have them so tightly coupled that it defeats the goal of the plugin itself.

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

        L 1 Reply Last reply
        1
        • SGaistS SGaist

          That you have a design issue.

          If you need your plugins to know a lot of stuff about other plugins then clearly there's something wrong going on.

          Are you sure that you need plugins at all ?

          The role of a plugin is to extend a functionality and if it's not there then the extension is simply not available. Here you have them so tightly coupled that it defeats the goal of the plugin itself.

          L Offline
          L Offline
          Luckless
          wrote on last edited by Luckless
          #14

          @SGaist according to https://doc.qt.io/qt-5/plugins-howto.html
          Qt provides two APIs for creating plugins:

          A high-level API for writing extensions to Qt itself: custom database drivers, image formats, text codecs, custom styles, etc.
          A low-level API for extending Qt applications.
          

          So I am making lower level APIs. And my plugins are extending my main Qt Application. Only the thing is PLugins may have dependency on each other too

          Basically I want to achieve collaborative development using Plugins, where each developer can work on his Qt plugin. And one plugin can have dependency on another.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Luckless
            wrote on last edited by
            #15

            Isnt Qt Plugins a good way to achieve collaborative development ?

            jsulmJ 1 Reply Last reply
            0
            • L Luckless

              Isnt Qt Plugins a good way to achieve collaborative development ?

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

              @Luckless said in Global function access to all plugins:

              Isnt Qt Plugins a good way to achieve collaborative development ?

              Can't you simply use shared libraries instead of plug-ins?

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

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Luckless
                wrote on last edited by
                #17

                Actually Earlier I was using Shared Libraries. But Later I came across QT Plugins, and the instance() function that QPluginLoader provides to get the object of root node of the plugin, which I believe is not provided by QLibrary.
                For this reason I went for Plugins over simple Shared Libraries. Is that bad @jsulm ?

                jsulmJ 1 Reply Last reply
                0
                • L Luckless

                  How can I make a Global function which can be accessed by my QApplication(main.cpp where all my Plugins are loaded) and to all Qt Plugins my QApplication loads ?
                  I am relatively new to Qt Plugins so an example would be nice.

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by
                  #18

                  @Luckless Sounds like singleton class. Create your own. Do what you want inside.

                  1 Reply Last reply
                  0
                  • L Luckless

                    Actually Earlier I was using Shared Libraries. But Later I came across QT Plugins, and the instance() function that QPluginLoader provides to get the object of root node of the plugin, which I believe is not provided by QLibrary.
                    For this reason I went for Plugins over simple Shared Libraries. Is that bad @jsulm ?

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

                    @Luckless said in Global function access to all plugins:

                    Is that bad @jsulm ?

                    The question is rather: do you need plug-ins? Plug-ins are like shared libraries but are loaded at runtime when activated (just like what QtCreator is doing). And as pointed out by others they should not depend on each other. So, if your plug-ins are always needed by your application then I don't see the point to implement them as plug-ins, make them normal shared libraries.

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

                    1 Reply Last reply
                    2
                    • L Offline
                      L Offline
                      Luckless
                      wrote on last edited by
                      #20

                      Lets say I revert back to my Shared library / QLibrary code.
                      How would I achieve the following:

                      @Luckless said in Global function access to all plugins:

                      To get the QObject instance of other plugins, via the central repo of objects(QHash(QString, QObject*))

                      And would it be any different if I try to achieve this in either Plugin or Shared Library case

                      jsulmJ 1 Reply Last reply
                      0
                      • L Luckless

                        Lets say I revert back to my Shared library / QLibrary code.
                        How would I achieve the following:

                        @Luckless said in Global function access to all plugins:

                        To get the QObject instance of other plugins, via the central repo of objects(QHash(QString, QObject*))

                        And would it be any different if I try to achieve this in either Plugin or Shared Library case

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

                        @Luckless If you do not use plug-ins there is no need to get instances of other plug-ins.
                        If you need use functionality of lib a in lib b then do it in the usual way: include a header file in b and use the functionality.

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

                        1 Reply Last reply
                        1

                        • Login

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