Results 1 to 19 of 19

Thread: Custom Widgets loading in Designer, but unable to find headers in Creator

  1. #1
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Custom Widgets loading in Designer, but unable to find headers in Creator

    Hi,

    I've created a set of custom widgets with plugins. My project file looks like so:

    Qt Code:
    1. CONFIG += designer \
    2. plugin \
    3. release
    4. TEMPLATE = lib
    5. TARGET = PCustomWidgetGroup
    6. HEADERS += pframe.h \
    7. punitspinbox.h \
    8. punitslider.h \
    9. pcustomwidgetgroupplugin.h \
    10. punitwidget.h
    11. SOURCES += pframe.cpp \
    12. punitspinbox.cpp \
    13. punitslider.cpp \
    14. punitwidget.cpp
    15. FORMS += pframe.ui \
    16. punitspinbox.ui \
    17. punitslider.ui
    18. target.path = $$[QT_INSTALL_PLUGINS]/designer
    19. INSTALLS += target
    To copy to clipboard, switch view to plain text mode 

    Despite the fact that I have the INSTALLS line, the *.a and *.dll files don't actually get copied to that folder. Up to now I've been manually copying them myself, although I would like to know why this occurs (but this is only a small problem atm...).

    Now, when I load QT Designer, all my custom widgets show up and work fine. Unfortunately, this isn't the case in any project I create in QT Creator. It has problems finding the header files at compile time. Of course, this makes sense to me, since it doesn't seem like the headers are being copied to any folder.

    I added the following line to my project file above, as per a tutorial online...

    Qt Code:
    1. INCLUDEPATH += $$QT_SOURCE_TREE/tools/designer/interfaces
    To copy to clipboard, switch view to plain text mode 

    But alas, still no luck. I also added the following to my current project's .pro file:

    Qt Code:
    1. LIBS += PCustomWidgetGroup
    To copy to clipboard, switch view to plain text mode 

    And nothing. I can't seem to find anything which adequately explains what folder my headers should be placed in, or how to do it automatically via the makefile. And, again, I'm unable to get the .a and .dll files copied without doing so manually.

    Perhaps there's just something I'm doing entirely wrong and someone could snap me out of it All help is greatly appreciated! Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Quote Originally Posted by Polnareff View Post
    Despite the fact that I have the INSTALLS line, the *.a and *.dll files don't actually get copied to that folder. Up to now I've been manually copying them myself, although I would like to know why this occurs (but this is only a small problem atm...).
    Are you running "make install" after the compilation (you might need superuser privileges)?

    Now, when I load QT Designer, all my custom widgets show up and work fine. Unfortunately, this isn't the case in any project I create in QT Creator. It has problems finding the header files at compile time. Of course, this makes sense to me, since it doesn't seem like the headers are being copied to any folder.
    And where did you copy the headers to?

    And nothing. I can't seem to find anything which adequately explains what folder my headers should be placed in, or how to do it automatically via the makefile. And, again, I'm unable to get the .a and .dll files copied without doing so manually.
    You can place the headers anywhere you want. Just make sure you add this directory to INCLUDEPATH variable in all projects that need to use those files.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Polnareff (19th May 2010)

  4. #3
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Quote Originally Posted by wysota View Post
    Are you running "make install" after the compilation (you might need superuser privileges)?
    Well I simply ran build from the QT Creator. I'm also doing this on my work computer, so it's very likely it has to do with user privileges. I'll look into it, thanks.

    Quote Originally Posted by wysota View Post
    You can place the headers anywhere you want. Just make sure you add this directory to INCLUDEPATH variable in all projects that need to use those files.
    Okay, I did this. The errors I am getting now:

    Qt Code:
    1. debug/mainwindow.o:C:\Documents and Settings\amaior\Desktop\Projects\IntegratedCustomWidgets/ui_mainwindow.h:54: undefined reference to `_imp___ZN6PFrameC1EP7QWidget'
    2. debug/mainwindow.o:C:\Documents and Settings\amaior\Desktop\Projects\IntegratedCustomWidgets/ui_mainwindow.h:61: undefined reference to `_imp___ZN12PUnitSpinBoxC1EP7QWidget'
    3. debug/mainwindow.o:C:\Documents and Settings\amaior\Desktop\Projects\IntegratedCustomWidgets/ui_mainwindow.h:68: undefined reference to `_imp___ZN11PUnitSliderC1EP7QWidget'
    To copy to clipboard, switch view to plain text mode 

    From a bit of research, I found that it may have to do with adding libs to my project...unsure though, currently I just add the includepath for the headers.
    Last edited by Polnareff; 19th May 2010 at 15:09.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Quote Originally Posted by Polnareff View Post
    Well I simply ran build from the QT Creator.
    Creator runs "make", not "make install".

    From a bit of research, I found that it may have to do with adding libs to my project...unsure though, currently I just add the includepath for the headers.
    That's not enough. You need to link the project against the actual code of the widget, either by compiling the widget files directly with your project or by linking to a library containing the widget implementation (like the plugin library). The plugin itself is only meant for Designer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    Polnareff (19th May 2010)

  7. #5
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Quote Originally Posted by wysota View Post
    That's not enough. You need to link the project against the actual code of the widget, either by compiling the widget files directly with your project or by linking to a library containing the widget implementation (like the plugin library). The plugin itself is only meant for Designer.
    By adding the header files and including it via the INCLUDEPATH, isn't that what I'm doing?

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    No. Header files only contain declarations of functions and classes. When you use Qt it is not enough to include Qt headers in your project, you need to link to actual Qt libraries (dlls), right? That's the same case here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    Polnareff (19th May 2010)

  10. #7
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Ah, that makes sense. Okay well I've re-compiled my widget with mvsc (mostly because I want to be able to add the widgets from QT Creator's designer), and copied the lib into a folder called lib in my project root. So I have

    /include/punitspinbox.h (there are others, but this is the only one I'm using at the moment)
    /lib/PCustomWidgetGroup.lib

    I've added the following lines to my project file:
    INCLUDEPATH += ./include
    LIBS += -lib -PCustomWidgetGroup

    The first problem I have is with the LIBS line...which I followed from tutorials. Either way, upon replacing it with an actual direct path to the lib file, it finds the lib file, but I get the following error:

    C:/Documents and Settings/amaior/Desktop/Projects/IntegratedCustomWidgets/ui_mainwindow.h:49: undefined reference to `_imp___ZN12PUnitSpinBoxC1EP7QWidget'

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Your LIBS line is surely incorrect. It should say LIBS += -lnameofthelibrary, i.e. -lmyplugin (if your lib is called myplugin.dll).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:

    Polnareff (19th May 2010)

  13. #9
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Quote Originally Posted by wysota View Post
    Your LIBS line is surely incorrect. It should say LIBS += -lnameofthelibrary, i.e. -lmyplugin (if your lib is called myplugin.dll).
    Thanks. I've fixed that, but the other error persists =/

  14. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Did you build the plugin with the same compiler you are using for compiling your projects? Also make sure you actually implemented the UnitSpinBox constructor taking a QWidget parameter. Remember about exporting the class from the DLL! In doubt, consult the documentation for Windows specifics.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #11
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    I've decided to stop building with the mvsc compiler, and just stick to the one that QT Creator uses. And yes, the UnitSpinBox constructor takes a QWidget parameter.

    Now I have two questions...

    1. I made a macro to export my classes to DLL, and want to put it in the class definition. Except since my classes are also exported to designer, I need to have both macros in the class definition. Unfortunately, the following doesn't seem to work:
    Qt Code:
    1. class SHAREDLIB_EXPORT QDESIGNER_WIDGET_EXPORT PUnitSpinBox : public PUnitWidget {
    To copy to clipboard, switch view to plain text mode 
    I also tried separating the macros by comma, with no success. What's the correct syntax for this?

    2. Currently building doesn't ever produce a *.lib file. Is that normal? What am I supposed to link against without it? (please excuse my lack of knowledge on this stuff, I'm still learning)

  16. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    You only need one macro, they both probably have the same contents.

    2. Currently building doesn't ever produce a *.lib file. Is that normal?
    If you don't have export macros then yes. That's why you need them
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #13
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Shortly before your reply I realized the macros were doing the same thing :P

    But that's just it, I've had the QDESIGNER_WIDGET_EXPORT macro in there the whole time, and I still don't have any lib file. Incase it's important, my .pro file is:

    Qt Code:
    1. CONFIG += designer \
    2. plugin \
    3. release
    4. TEMPLATE = lib
    5. DEFINES += SHAREDLIB_LIBRARY
    6.  
    7. HEADERS += pcustomwidgetgroupplugin.h \
    8. include(CustomWidgets.pri)
    9.  
    10. target.path = $$[QT_INSTALL_PLUGINS]/designer
    11. INSTALLS += target
    To copy to clipboard, switch view to plain text mode 

    Am I missing something to create the lib file?

  18. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    What's in CustomWidgets.pri?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #15
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Qt Code:
    1. HEADERS += pframe.h \
    2. punitspinbox.h \
    3. punitslider.h \
    4. punitwidget.h \
    5. sharedlib_global.h
    6. SOURCES += pframe.cpp \
    7. punitspinbox.cpp \
    8. punitslider.cpp \
    9. punitwidget.cpp
    10. FORMS += pframe.ui \
    11. punitspinbox.ui \
    12. punitslider.ui
    To copy to clipboard, switch view to plain text mode 

    I only just introduced that. Those were originally in the pro file. It's just to clean it up a bit.

  20. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Do all your classes contain export macros?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  21. #17
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    These are my classes (--> denotes child class, and * denotes containing export macro)

    • PFrame*
    • PUnitWidget
    • --> PUnitSlider*
    • --> PUnitSpinBox*

    //Plugins...
    • WidgetPlugin
    • PFramePlugin
    • PUnitSliderPlugin
    • PUnitSpinBoxPlugin
    • PCustomWidgetGroupPlugin (Q_EXPORT_PLUGIN2 is called on this class)


    Do I need to be exporting all of them?

  22. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    You should export all widget classes but if at least one class contains export macro, the .lib (or .a in case of MinGW) file should be created.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  23. The following user says thank you to wysota for this useful post:

    Polnareff (21st May 2010)

  24. #19
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widgets loading in Designer, but unable to find headers in Creator

    Well, believe it or not, I've gotten it to work! Thank you so much, by the way, for tolerating with me I understand this a lot better now, so it certainly helped.

Similar Threads

  1. Adding Custom Widgets to the QT Designer
    By Polnareff in forum Qt Programming
    Replies: 1
    Last Post: 17th May 2010, 22:31
  2. custom widgets in qt creator 4.6
    By tentakel in forum Newbie
    Replies: 3
    Last Post: 4th May 2010, 23:05
  3. Replies: 3
    Last Post: 17th November 2009, 15:43
  4. add custom widgets to Qt Creator
    By yagabey in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2008, 18:26
  5. problem loading custom plugin on Qt Designer 4
    By raman_31181 in forum Qt Tools
    Replies: 18
    Last Post: 26th September 2008, 10:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.