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. QPluginLoader : How to load several times the same plugin

QPluginLoader : How to load several times the same plugin

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 6.7k 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.
  • mistralegnaM Offline
    mistralegnaM Offline
    mistralegna
    wrote on last edited by
    #1

    Hello,

    I have developped several plugins I load inside an GUI application.
    The first time I load the plugin, all the stuff is working fine, but I didn't manage to load the same plugin another time.

    Each plugin is a widget that can be shown one or more times with different parameters.

    I apologize for the lack of code, but it is quite a basic code to load a plugin (get a plugin instance, and cast it into the parent interface).

    Thanks for your answers !

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      To show the widget multiple times, you don't need to load the plugin multiple times. That just doesn't make any sense. Just have your plugin's factory method produce a new instance of your widget.

      1 Reply Last reply
      0
      • mistralegnaM Offline
        mistralegnaM Offline
        mistralegna
        wrote on last edited by
        #3

        But, do we agree that each time user want to get access to the plugin, I have to do this :

        @
        QPluginLoader loader(pluginToLoadFilePath);
        QObject *pluginInstance = loader.instance();
        IPlugin *plugin = qobject_cast<IPlugin *>(pluginInstance);

        // The interface has a virtual function getWidget()
        // returning the widget associated with this plugin.
        // Moreover, the plugin has a function setData()
        // to set the data to show.

        plugin->getWidget()->show();
        @

        It works well the first time, but if user wants to use the same plugin with another kind of data (it means another plugin).

        I just had this idea : shall it work if in the function getWidget(), instead of returning a pointer on the current object deriving either from QWidget and from the plugin interface, I return a new widget ?

        I forgot to precise english is not my maternal language, so excuse my poor english (including comprehension).

        Thanks a lot.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          No, we don't. You just load the plugin once. You only need QPluginLoader that once. You just ask for the instance for than once. Or, better yet, you have your plugin not return the actual class that you want, but a factory that can create instances of that class. Then, if you need another instance, you simply ask the factory to produce one for you.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            The pluginloader loads code into your program. All code is identified by symbol names (your methods, etc. with a bit of added name mangling to encode type information when using C++). You need to make sure the right symbols are found whenever you need to access one of them (e.g. you call a method).

            So for a plugin to load several times you would need to make sure all its symbols are changed before loading it a second time. Otherwise the symbols of one of the plugins will be hidden behind those of the other which will most likely cause some really interesting effects.

            So, no you can not load the same plugin twice. You can use the code of one plugin several times though.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tallia1
              wrote on last edited by
              #6

              I found "this post":http://lists.trolltech.com/qt-interest/2005-12/msg00281.html quite useful.

              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