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.
  • raven-worxR raven-worx

    @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)

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on 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

    kshegunovK 1 Reply Last reply
    0
    • raven-worxR raven-worx

      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.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on 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
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on 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

        ILI 1 Reply Last reply
        0
        • raven-worxR raven-worx

          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.

          ILI Offline
          ILI Offline
          IL
          wrote on 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
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on 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

            ILI 1 Reply Last reply
            0
            • raven-worxR raven-worx

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

              ILI Offline
              ILI Offline
              IL
              wrote on 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.

              kshegunovK 1 Reply Last reply
              0
              • ILI IL

                @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.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on 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

                ILI 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  @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.

                  ILI Offline
                  ILI Offline
                  IL
                  wrote on 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?

                  kshegunovK raven-worxR 2 Replies Last reply
                  0
                  • ILI IL

                    @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?

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on 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

                    ILI 1 Reply Last reply
                    0
                    • ILI IL

                      @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?

                      raven-worxR Offline
                      raven-worxR Offline
                      raven-worx
                      Moderators
                      wrote on 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
                      • kshegunovK kshegunov

                        @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.

                        ILI Offline
                        ILI Offline
                        IL
                        wrote on 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?

                        kshegunovK 1 Reply Last reply
                        0
                        • ILI IL

                          @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?

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on 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

                          ILI 1 Reply Last reply
                          0
                          • kshegunovK kshegunov

                            @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.

                            ILI Offline
                            ILI Offline
                            IL
                            wrote on 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

                            • Login

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