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. How to create and load UI plugins?
Forum Updated to NodeBB v4.3 + New Features

How to create and load UI plugins?

Scheduled Pinned Locked Moved Solved General and Desktop
pluginloadergui
20 Posts 3 Posters 11.6k Views 2 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.
  • K kshegunov
    22 Dec 2015, 20:29

    @IL
    Hello,
    Plugins that contain GUI are in no way different from plugins that don't contain GUI. You create, set up and build your plugin the same way, whether it has GUI classes, or doesn't. This is the reason that QtCreator doesn't have anything specifically related to GUI plugins, they are simply a shared library that is loaded at runtime with the help of the QPluginLoader class. Any class, form or resource can reside in the shared library, just the same way it can reside in an application. So, to create Ui in a plugin, you follow all the same basic steps you take when you do it in your application project - create forms, create classes and so on. Take a look at this example, where plugins are created and used to extend the GUI part of an application. I hope this will help you to set your plugin up.

    @raven-worx said:

    Hint: if you declare this method as a slot or with Q_INVOKABLE you can call it even without knowing it's exact type (no need to include implementation headers)

    You don't include implementation headers in any case. The application defines the acceptable/expected interfaces and the plugin creates the instances behind these abstract classes. I don't see how making a function invokable through the meta-object system helps you.

    R Offline
    R Offline
    raven-worx
    Moderators
    wrote on 23 Dec 2015, 07:40 last edited by
    #6

    @kshegunov said:

    You don't include implementation headers in any case. The application defines the acceptable/expected interfaces and the plugin creates the instances behind these abstract classes. I don't see how making a function invokable through the meta-object system helps you.

    And how does this magic happen?
    When we really talk about plugins which are "loosely coupled" with the executable how do you call custom defined methods of the interface when you don't tell the compiler the type of the created instance?
    That's why i suggested the Q_INVOKABLE method, since you receive a QObject you can use QMetaObject::invokeMethod() on it...
    For the plugin itself of course you do not need to include any headers, since they already come with Qt.

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    K 1 Reply Last reply 23 Dec 2015, 10:43
    0
    • R raven-worx
      23 Dec 2015, 07:40

      @kshegunov said:

      You don't include implementation headers in any case. The application defines the acceptable/expected interfaces and the plugin creates the instances behind these abstract classes. I don't see how making a function invokable through the meta-object system helps you.

      And how does this magic happen?
      When we really talk about plugins which are "loosely coupled" with the executable how do you call custom defined methods of the interface when you don't tell the compiler the type of the created instance?
      That's why i suggested the Q_INVOKABLE method, since you receive a QObject you can use QMetaObject::invokeMethod() on it...
      For the plugin itself of course you do not need to include any headers, since they already come with Qt.

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 23 Dec 2015, 10:43 last edited by
      #7

      @raven-worx

      When we really talk about plugins which are "loosely coupled" with the executable how do you call custom defined methods of the interface when you don't tell the compiler the type of the created instance?

      Sorry, I don't understand what you mean.
      Doesn't the knowledge about the exact instance type really defeat the purpose of a plugin? This'd mean that you'll have to know when compiling your application what plugins are potentially used ...

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • R raven-worx
        22 Dec 2015, 12:43

        @IL said:

        I believe that the second option is the one that I need but QT creator doesn’t give you the option to create library plugin that contains UI, it only asking you about dynamic or static library, and I need it to be with UI.

        Simply create a Lib project in QtCreator.
        Now the question is if you want a

        • shared library (linked dependency - program doesn't run without it), or
        • a Qt-plugin (discovered and loaded at runtime - program also runs without it)

        Then simply add a UI file manually to your QtCreator project.
        Right click on your project -> Add New -> Qt -> Qt Designer Form Class

        Then you can either define a method on the library/plugin interface to create a instance of your UI class and return it.

        Hint: if you declare this method as a slot or with Q_INVOKABLE you can call it even without knowing it's exact type (no need to include implementation headers)

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 23 Dec 2015, 10:57 last edited by raven-worx
        #8

        For example this is how Qt does it:
        (using the - unfortunately undocumented - QFactoryLoader class)

        1. look in predefined folders for plugins (imageformats, etc) -> see QCoreApplication::addLibraryPath()
        2. then it tries to load the (predefined) plugin interface, which is already given by the folder where it is loaded from
        3. the plugin interface is already linked into the Qt binaries (e.g. QImageIOPlugin, etc)

        so when you write a custom plugin you can derive it from QGenericPlugin and implement it's create() method, which returns a QObject. This QObject is your UI instance for example. Or even a wrapper widget where you call convenience (invokable) methods, like i was talking about.

        So the question is if plugins or a shared library is desired here.

        Plugins also of course have the big advantage that you do not need to recompile the application when you add functionality via a plugin.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        K 1 Reply Last reply 23 Dec 2015, 11:23
        0
        • R raven-worx
          23 Dec 2015, 10:57

          For example this is how Qt does it:
          (using the - unfortunately undocumented - QFactoryLoader class)

          1. look in predefined folders for plugins (imageformats, etc) -> see QCoreApplication::addLibraryPath()
          2. then it tries to load the (predefined) plugin interface, which is already given by the folder where it is loaded from
          3. the plugin interface is already linked into the Qt binaries (e.g. QImageIOPlugin, etc)

          so when you write a custom plugin you can derive it from QGenericPlugin and implement it's create() method, which returns a QObject. This QObject is your UI instance for example. Or even a wrapper widget where you call convenience (invokable) methods, like i was talking about.

          So the question is if plugins or a shared library is desired here.

          Plugins also of course have the big advantage that you do not need to recompile the application when you add functionality via a plugin.

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 23 Dec 2015, 11:23 last edited by
          #9

          @raven-worx
          Hello,
          Maybe there is a misunderstanding. I fathomed IL's question to be that he wants to write plugins for his own program not for Qt. Then you define your interfaces and load your applications plugins with the QPluginLoader class. The QObject you get is the actual plugin class that you query for functionality by means of the interfaces you've defined in your application (as it is done in the plug & paint example I've linked). There is no QGenericPlugin plugin there. You just subclass QObject and through the desired interfaces you provide the instances you need. The QObject is just an entry point for your plugin and your application has no knowledge of the implementation specific details. Your plugin on the other hand has to include the interfaces it's implementing (which is normal) but not the other way around. See here the low-level API I'm talking about.

          Kind regards.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 23 Dec 2015, 11:39 last edited by
            #10

            yes, maybe this was a long shot from me.
            But basically it's the same mechanism i was talking about.
            Just Qt (QFactoryLoader) does most of the work under the hood automatically.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            I 1 Reply Last reply 23 Dec 2015, 12:15
            0
            • R raven-worx
              23 Dec 2015, 11:39

              yes, maybe this was a long shot from me.
              But basically it's the same mechanism i was talking about.
              Just Qt (QFactoryLoader) does most of the work under the hood automatically.

              I Offline
              I Offline
              IL
              wrote on 23 Dec 2015, 12:15 last edited by
              #11

              @raven-worx
              Hello and thanks,
              Regarding your first comment/reply -
              Quote:
              Simply create a Lib project in QtCreator.
              Now the question is if you want a

              • list itemshared library (linked dependency - program doesn't run without it), or
              • list itema Qt-plugin (discovered and loaded at runtime - program also runs without it)

              Then simply add a UI file manually to your QtCreator project.
              Right click on your project -> Add New -> Qt -> Qt Designer Form Class
              End of Quote
              The second option is what I need, and I already did that but after adding UI into the QT plugin, the project doesn't compiled any more, it complain about missing files, like ui_<project-name>.h and more.

              • What is the correct way to do that?

              Best regards,
              IL

              1 Reply Last reply
              0
              • R Offline
                R Offline
                raven-worx
                Moderators
                wrote on 23 Dec 2015, 12:21 last edited by
                #12

                try re-running qmake.
                (Right click on project -> Run qmake)

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                I 1 Reply Last reply 23 Dec 2015, 13:04
                0
                • R raven-worx
                  23 Dec 2015, 12:21

                  try re-running qmake.
                  (Right click on project -> Run qmake)

                  I Offline
                  I Offline
                  IL
                  wrote on 23 Dec 2015, 13:04 last edited by
                  #13

                  @raven-worx
                  same thing,
                  Running qmake is ok but build failed
                  it should at-least generate ui_project.h file but it doesnt do that.

                  K 1 Reply Last reply 23 Dec 2015, 13:14
                  0
                  • I IL
                    23 Dec 2015, 13:04

                    @raven-worx
                    same thing,
                    Running qmake is ok but build failed
                    it should at-least generate ui_project.h file but it doesnt do that.

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 23 Dec 2015, 13:14 last edited by
                    #14

                    @IL
                    Do you have your forms in your project, like this:

                    FORMS += myform.ui
                    

                    I don't know what IDE you're using, for me QtCreator does this automatically, but it's possible it's different for you.

                    Read and abide by the Qt Code of Conduct

                    I 1 Reply Last reply 23 Dec 2015, 13:49
                    0
                    • K kshegunov
                      23 Dec 2015, 13:14

                      @IL
                      Do you have your forms in your project, like this:

                      FORMS += myform.ui
                      

                      I don't know what IDE you're using, for me QtCreator does this automatically, but it's possible it's different for you.

                      I Offline
                      I Offline
                      IL
                      wrote on 23 Dec 2015, 13:49 last edited by
                      #15

                      @kshegunov
                      Yes I do have the file in my form project.
                      The thing is when I create new QT widgets application project, QtCreator creat the file.ui file and under the output folder build-...-Debug it create a ui_file.h which contains all the UI stuff
                      But when I create QtPlugin library project and add UI form, the ui_file doesn't create eventhough it adding include of it.
                      I am working with QT-5.5.0 and Qt Creator 3.4.2

                      Any idea?

                      K R 2 Replies Last reply 23 Dec 2015, 13:57
                      0
                      • I IL
                        23 Dec 2015, 13:49

                        @kshegunov
                        Yes I do have the file in my form project.
                        The thing is when I create new QT widgets application project, QtCreator creat the file.ui file and under the output folder build-...-Debug it create a ui_file.h which contains all the UI stuff
                        But when I create QtPlugin library project and add UI form, the ui_file doesn't create eventhough it adding include of it.
                        I am working with QT-5.5.0 and Qt Creator 3.4.2

                        Any idea?

                        K Offline
                        K Offline
                        kshegunov
                        Moderators
                        wrote on 23 Dec 2015, 13:57 last edited by
                        #16

                        @IL
                        When I go to the New file or project ... menu and then from the sidebar I select Library, I can choose from:

                        1. C++ library - this is what you actually want
                        2. QtQuick 1 Extension plugin - this is for QtQuick (not relevant to your case)
                        3. QtQuick 2 Extension plugin - this is for QtQuick 2 (not relevant to your case as well)
                        4. Qt Creator Plugin - unless you want to create plugins for QtCreator, this is not your project type.

                        I don't have a QtPlugin library project in my list.

                        Read and abide by the Qt Code of Conduct

                        I 1 Reply Last reply 23 Dec 2015, 14:13
                        0
                        • I IL
                          23 Dec 2015, 13:49

                          @kshegunov
                          Yes I do have the file in my form project.
                          The thing is when I create new QT widgets application project, QtCreator creat the file.ui file and under the output folder build-...-Debug it create a ui_file.h which contains all the UI stuff
                          But when I create QtPlugin library project and add UI form, the ui_file doesn't create eventhough it adding include of it.
                          I am working with QT-5.5.0 and Qt Creator 3.4.2

                          Any idea?

                          R Offline
                          R Offline
                          raven-worx
                          Moderators
                          wrote on 23 Dec 2015, 14:06 last edited by
                          #17

                          @IL
                          seems like this is a bug in Qt5's qmake. That the build steps are not created correctly when TEMPLATE=lib
                          It works perfectly fine in Qt4.

                          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                          If you have a question please use the forum so others can benefit from the solution in the future

                          1 Reply Last reply
                          0
                          • K kshegunov
                            23 Dec 2015, 13:57

                            @IL
                            When I go to the New file or project ... menu and then from the sidebar I select Library, I can choose from:

                            1. C++ library - this is what you actually want
                            2. QtQuick 1 Extension plugin - this is for QtQuick (not relevant to your case)
                            3. QtQuick 2 Extension plugin - this is for QtQuick 2 (not relevant to your case as well)
                            4. Qt Creator Plugin - unless you want to create plugins for QtCreator, this is not your project type.

                            I don't have a QtPlugin library project in my list.

                            I Offline
                            I Offline
                            IL
                            wrote on 23 Dec 2015, 14:13 last edited by
                            #18

                            @kshegunov
                            Good,
                            Now if you go to New Project and select C++ Library
                            Under Type you will have three options:

                            • shared library
                            • statically linked library
                            • Qt Plugin

                            I choose the third option, can you see that?

                            K 1 Reply Last reply 23 Dec 2015, 14:15
                            0
                            • I IL
                              23 Dec 2015, 14:13

                              @kshegunov
                              Good,
                              Now if you go to New Project and select C++ Library
                              Under Type you will have three options:

                              • shared library
                              • statically linked library
                              • Qt Plugin

                              I choose the third option, can you see that?

                              K Offline
                              K Offline
                              kshegunov
                              Moderators
                              wrote on 23 Dec 2015, 14:15 last edited by
                              #19

                              @IL
                              Aha, I see what you mean. Well, you won't be extending Qt, but your application, so choose Shared Library from the dropdown, not Qt Plugin.

                              Read and abide by the Qt Code of Conduct

                              I 1 Reply Last reply 23 Dec 2015, 14:31
                              0
                              • K kshegunov
                                23 Dec 2015, 14:15

                                @IL
                                Aha, I see what you mean. Well, you won't be extending Qt, but your application, so choose Shared Library from the dropdown, not Qt Plugin.

                                I Offline
                                I Offline
                                IL
                                wrote on 23 Dec 2015, 14:31 last edited by
                                #20

                                @kshegunov
                                Yap, Thanks, Thanks. :-)
                                Now It's generate all the required files, I also need to add QWidgets in Select Required Models.

                                Best Regards,
                                IL

                                1 Reply Last reply
                                0

                                15/20

                                23 Dec 2015, 13:49

                                • Login

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