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. [Solved]My custom widget will not show in Designer
Forum Updated to NodeBB v4.3 + New Features

[Solved]My custom widget will not show in Designer

Scheduled Pinned Locked Moved General and Desktop
19 Posts 4 Posters 4.9k 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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by
    #9

    I did felt a little bit of guilt while copying the header file in Qt, but what else is there to do, my widget needs the header file, and if in the future I create an actually useful widget that I want to use all the time wouldn't it be better than having to copy that header for each project?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #10

      I actually never create my own plugins because to me they are more hassle than they're worth, so take my opinion with a grain of salt, but here it is:

      I would treat the plugin as any other shared 3rd party library you use (because they're basically just that). Create a directory for it where you keep your libs with "include", "lib" and "bin" sub-directories and put your .h, .lib(.a), and .dll(.so) files there.
      When you create multiple projects using them just add the proper LIBS and INCLUDEPATH info into the project's .pro file.

      1 Reply Last reply
      0
      • ealioneE Offline
        ealioneE Offline
        ealione
        wrote on last edited by
        #11

        Makes sense actually. I just did this as a small exercise to see how it would be possible to add another widget to the designer, but I believe that your suggestion is quite sensible. Besides I would have to distribute those plugins so having the properly organised is the smart thing to do.

        Going back to the plugin though my link problem persists even though I added

        @LIBS += -LC:/Users/PC/Downloads/plugin/analogclockplugin.lib@

        as well as other variations such as

        @LIBS += -LC:\Users\PC\Downloads\plugin\analogclockplugin.lib@

        @LIBS += -LC:\Users\PC\Downloads\plugin -lanalogclockplugin@

        @LIBS += C:\Users\PC\Downloads\plugin\analogclockplugin.lib@

        This is on windows and the actual plugin is named "analogclockplugin.lib" and the dll "analogclockplugin.dll"

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #12

          Should be:
          @
          LIBS += -LC:/Users/PC/Downloads/plugin -lanalogclockplugin
          @
          Note the -l (lowercase L) and omission of the file extension (.lib),
          -L specifies directory, -l library name.

          If you want to use backslashes you need to double them e.g.
          @
          LIBS += -LC:\Users\PC\Downloads\plugin -lanalogclockplugin
          @
          otherwise they are threated as escape sequences \U, \P, \D and \p which are invalid

          1 Reply Last reply
          0
          • ealioneE Offline
            ealioneE Offline
            ealione
            wrote on last edited by
            #13

            Yes I forgot to mention it, this was the first thing I tried since you suggested it in the first place, yet i still get the unresolved external

            @mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall IconEditor::IconEditor(class QWidget *)" (??0IconEditor@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall Ui_MainWindow::setupUi(class QMainWindow *)" (?setupUi@Ui_MainWindow@@QAEXPAVQMainWindow@@@Z)@

            No idea why, this is not the first time I'm using an external library. I successfully did it with many database drivers in the past.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #14

              After you edit .pro be sure to re-run qmake (from the Build menu) so it will pick up the changes.

              1 Reply Last reply
              0
              • ealioneE Offline
                ealioneE Offline
                ealione
                wrote on last edited by
                #15

                There must be something on a deeper level here that I am getting wrong.

                The original plugin was created in this way:

                A .cpp and .h file named analogclock.cpp and analogclock.h respectively.

                I then did another project, as describer by the tutorial, comprised by analogclockplugin.h and analogclockplugin.cpp.

                In the includeFile() function for the plugin I added analogclock.h.

                After that when trying to run a test project containing this plugin, and after modifying my pro file including the created lib, and having copied analogclock.h in Qt's include directory I get the link error mentioned.

                I then tried removing analogclock.h from there and instead putting

                @HEADERS += mainwindow.h
                analogclock.h@

                in my pro file (after having of curse copied the header file in my project directory) I get an unresolved external for every function inside the header file.

                Trying to add

                @INCLUDEPATH += "C:/Users/PC/Downloads/plugin/inc"@

                results in the header not being found, even though from the little I know it should work.

                Am I forgetting to include something, or is it indeed the case that I am doing the whole process wrong?

                EDIT

                After reading "this":https://qt-project.org/forums/viewthread/31454 I see that I must have (for the same widget) a designer plugin and also a library, something that was not mentioned in the docs. Is this indeed the case? and if yes how do those two differ (in the pro file settings I mean)?

                W 1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #16

                  Ugh.. there's an important distinction that you missed and I have followed along by mistake. Sorry for that.

                  In your app using the custom widget you should not link to the plugin lib. It's for the designer only.
                  In your app you should either include the analogclock.cpp in the project or create a separate project that builds a lib of the class and link to that, not the plugin lib.

                  Basically a class library and a plugin library that displays that class in the designer are two different projects, so you're linking against the wrong thing. the lib you have exposes the plugin class, not your custom widget class.

                  1 Reply Last reply
                  0
                  • ealioneE Offline
                    ealioneE Offline
                    ealione
                    wrote on last edited by
                    #17

                    I knew I'd confuse you sooner or later, it's a personal skill of mine. I hope whoever reads this will be able to easily understand the solution through my multitude of posts.

                    1 Reply Last reply
                    0
                    • ealioneE ealione

                      There must be something on a deeper level here that I am getting wrong.

                      The original plugin was created in this way:

                      A .cpp and .h file named analogclock.cpp and analogclock.h respectively.

                      I then did another project, as describer by the tutorial, comprised by analogclockplugin.h and analogclockplugin.cpp.

                      In the includeFile() function for the plugin I added analogclock.h.

                      After that when trying to run a test project containing this plugin, and after modifying my pro file including the created lib, and having copied analogclock.h in Qt's include directory I get the link error mentioned.

                      I then tried removing analogclock.h from there and instead putting

                      @HEADERS += mainwindow.h
                      analogclock.h@

                      in my pro file (after having of curse copied the header file in my project directory) I get an unresolved external for every function inside the header file.

                      Trying to add

                      @INCLUDEPATH += "C:/Users/PC/Downloads/plugin/inc"@

                      results in the header not being found, even though from the little I know it should work.

                      Am I forgetting to include something, or is it indeed the case that I am doing the whole process wrong?

                      EDIT

                      After reading "this":https://qt-project.org/forums/viewthread/31454 I see that I must have (for the same widget) a designer plugin and also a library, something that was not mentioned in the docs. Is this indeed the case? and if yes how do those two differ (in the pro file settings I mean)?

                      W Offline
                      W Offline
                      WolfgangGriech
                      wrote on last edited by
                      #18

                      @ealione said in [Solved]My custom widget will not show in Designer:

                      After reading "this":https://qt-project.org/forums/viewthread/31454 I see that I must have (for the same widget) a designer plugin and also a library, something that was not mentioned in the docs. Is this indeed the case? and if yes how do those two differ (in the pro file settings I mean)?

                      I'm well aware of that this thread is already 10 years old, but anyway guys like myself are still reading this until today. So to clarify the statements above, it is NOT true that you'll need 2 different libraries for the designer plugin supplied to QtCreator / QtWidgetDesigner, and the widget library used for linking the contained widgets to your own code. We're happily using the very same library for both purposes, since Qt4.7 or even earlier, until the latest and greatest Qt6.8. Of course there has to be the appropriate interface information supplied for those 2 purposes, but all this can reside in 1 library only.

                      SGaistS 1 Reply Last reply
                      0
                      • W WolfgangGriech

                        @ealione said in [Solved]My custom widget will not show in Designer:

                        After reading "this":https://qt-project.org/forums/viewthread/31454 I see that I must have (for the same widget) a designer plugin and also a library, something that was not mentioned in the docs. Is this indeed the case? and if yes how do those two differ (in the pro file settings I mean)?

                        I'm well aware of that this thread is already 10 years old, but anyway guys like myself are still reading this until today. So to clarify the statements above, it is NOT true that you'll need 2 different libraries for the designer plugin supplied to QtCreator / QtWidgetDesigner, and the widget library used for linking the contained widgets to your own code. We're happily using the very same library for both purposes, since Qt4.7 or even earlier, until the latest and greatest Qt6.8. Of course there has to be the appropriate interface information supplied for those 2 purposes, but all this can reside in 1 library only.

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #19

                        @WolfgangGriech hi,

                        From memory, the suggestion to have a plug-in and separate library is to keep the dependencies down to a minimum because otherwise you would pull the designer library into your application.

                        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

                        • Login

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