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. 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.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.
  • L Offline
    L Offline
    Luckless
    wrote on last edited by Luckless
    #1

    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 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What do you need such a global function for ?

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

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

        I wish to make a convenience function which reads from a QHash that contains (QString, Plugin QObject*) pair, and returns the QObject* for the string passed as argument

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

          And what use would the plugin have if this function ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - 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 Luckless
            #5

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

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

              That sounds a bit strange. If I understand correctly, you want your plugins to access other plugins but they might not be loaded. Can you explain the goal of your design ?

              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
              0
              • SGaistS SGaist

                That sounds a bit strange. If I understand correctly, you want your plugins to access other plugins but they might not be loaded. Can you explain the goal of your design ?

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

                @SGaist
                In my main.cpp I am loading the Plugins in a specific order so that, if I want to use a QObject Instance of one plugin, it would have already been loaded before I use it in another plugin.
                Basically I am trying to create a way to manage the QObject instance of plugins, such that I can access them by simply access any of them by passing their name(QString in the hash) from other plugins.

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Plugins should not rely on each other -esp. not the way you're doing it. If a plugin needs another plugin than it should be resolved inside the plugin, not externally.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

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

                    Heres an example of what I am trying to do:
                    I have 1 plugin (say View plugin) which has a qml being loaded into a QQuickItem, where I am making a custom graph plot. Relating to this I have a model which supplies me with data for points to plot (in another Plugin, say Model Plugin).
                    Like this I have quite a few View and model plugins and my main.cpp loads them all using QPLuginLoader and arranges them in a layout defined in main.qml(loaded by a QQuickView).
                    So, I need these model and View Plugin's QObject instance to be available to other plugins. That is why I was trying to make a global class/function which could handle this.

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

                      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.

                      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

                        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

                                          • Login

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