Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: using a custom widget

  1. #1
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default using a custom widget

    Hi
    So I have a custom widget and want to use it in another project.
    In the .pro file for the new project I have
    Qt Code:
    1. LIBS += C://QTProjects/cccc-build-desktop/debug/mycustomwidgetplugin.dll
    To copy to clipboard, switch view to plain text mode 
    When I compile the project I get
    Qt Code:
    1. debug/MainWindow.o:C:\QTProjects\cccc-build-desktop/./ui_MainWindow.h:43: undefined reference to `MyCustomWidget::MyCustomWidget(QWidget*)'
    To copy to clipboard, switch view to plain text mode 

    Any ideas?

    Graham

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    did you specify in your project where to find the headers of your custom widgets?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using a custom widget

    Hi
    I have hard coded these for now
    #include "C:/QTProjects/MyCustomWidget/MyCustomWidget.h"

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    where?
    The error comes from an ui file - and it gets generated by the uic... if you are using your custom widget there - you should promote a widget to your custom widget so that the uic will include the correct file.
    Last edited by high_flyer; 21st March 2011 at 15:24.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using a custom widget

    hi
    I have now added the include path the .pro file
    My custom widget is built in a dll and is accessible in QtDesigner (although not in QtCreator)
    To get my application that uses the custom widget to compile I added an include path to the . pro file
    I also added the dll to the LIBS -
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2011-03-21T11:54:03
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. TARGET = cccc
    10. TEMPLATE = app
    11.  
    12.  
    13. SOURCES += main.cpp\
    14. MainWindow.cpp
    15.  
    16. HEADERS += MainWindow.h
    17.  
    18. FORMS += MainWindow.ui
    19.  
    20. INCLUDEPATH = C:/QTProjects/MyCustomWidget
    21. win32::LIBS += C:/QTProjects/MyCustomWidget-build-desktop/release/mycustomwidgetplugin.dll
    To copy to clipboard, switch view to plain text mode 

    When I build I get a undefined reference -
    /ui_MainWindow.h:43: undefined reference to `MyCustomWidget::MyCustomWidget(QWidget*)'

    I am struggling to understand why this is

    Any help appreciated

    Graham

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    I am struggling to understand why this is
    read my last post again.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using a custom widget

    Hi
    In Qt Designer I can see my custom widget and can drag it onto a form.
    This generates a ui file with an #include for the custom widget, which is located because of the INCLUDEPATH directive in the .pro file.
    If I drag a widget onto the form and try to promote it I get an error stating that the class already exists
    So I am confused!!

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    Hi
    In Qt Designer I can see my custom widget and can drag it onto a form.
    This generates a ui file with an #include for the custom widget, which is located because of the INCLUDEPATH directive in the .pro file.
    That piece of information you want to give at the beginning, and that is - that you have a designer plug in for your custom widget!!
    So there is no need for promotion.

    does your custom widget have a constructor that take a QWidget parent defined?
    Post the header for your custom widget.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using a custom widget

    Header File
    Qt Code:
    1. #ifndef MYCUSTOMWIDGET_H
    2. #define MYCUSTOMWIDGET_H
    3.  
    4. #include <QtGui/QWidget>
    5.  
    6. class MyCustomWidget : public QWidget
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. MyCustomWidget(QWidget *parent = 0);
    12. };
    13.  
    14. #endif
    To copy to clipboard, switch view to plain text mode 

    cpp
    Qt Code:
    1. #include "MyCustomWidget.h"
    2.  
    3. MyCustomWidget::MyCustomWidget(QWidget *parent) :
    4. QWidget(parent)
    5. {
    6. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for your help!

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    ok, show the include section of ui_MainWindow.h
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using a custom widget

    Here ya go
    Qt Code:
    1. #ifndef UI_MAINWINDOW_H
    2. #define UI_MAINWINDOW_H
    3.  
    4. #include <QtCore/QVariant>
    5. #include <QtGui/QAction>
    6. #include <QtGui/QApplication>
    7. #include <QtGui/QButtonGroup>
    8. #include <QtGui/QHeaderView>
    9. #include <QtGui/QMainWindow>
    10. #include <QtGui/QMenuBar>
    11. #include <QtGui/QStatusBar>
    12. #include <QtGui/QToolBar>
    13. #include <QtGui/QWidget>
    14. #include "MyCustomWidget.h"
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    and the custom widget header is under C:/QTProjects/MyCustomWidget?
    Then I don't see where the problem is...
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  13. #13
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using a custom widget


    I found this link
    http://stackoverflow.com/questions/2...491825#2491825
    But don't really know how to create the other lib

  14. #14
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    you are getting a compile error, not a link error.
    You have a definitive path problem that's all, I just can't tell where.
    What is said in that post you linked to is not correct.
    I link my apps to my custom widgets against their designer plugin dll with no problem.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  15. #15
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using a custom widget

    Hi
    Im not certain that its a compiler error
    Here is the output from the build
    Qt Code:
    1. Running build steps for project cccc...
    2. Starting: "C:/mingw/bin/mingw32-make.exe" clean -w
    3. mingw32-make: Entering directory `C:/QTProjects/cccc-build-desktop'
    4.  
    5. C:/mingw/bin/mingw32-make -f Makefile.Release clean
    6.  
    7. mingw32-make[1]: Entering directory `C:/QTProjects/cccc-build-desktop'
    8.  
    9. del release\moc_MainWindow.cpp
    10.  
    11. del ui_MainWindow.h
    12.  
    13. del release\main.o release\MainWindow.o release\moc_MainWindow.o
    14.  
    15. mingw32-make[1]: Leaving directory `C:/QTProjects/cccc-build-desktop'
    16.  
    17. C:/mingw/bin/mingw32-make -f Makefile.Debug clean
    18.  
    19. mingw32-make[1]: Entering directory `C:/QTProjects/cccc-build-desktop'
    20.  
    21. del debug\moc_MainWindow.cpp
    22.  
    23. del ui_MainWindow.h
    24.  
    25. del debug\main.o debug\MainWindow.o debug\moc_MainWindow.o
    26.  
    27. mingw32-make[1]: Leaving directory `C:/QTProjects/cccc-build-desktop'
    28.  
    29. mingw32-make: Leaving directory `C:/QTProjects/cccc-build-desktop'
    30.  
    31. Could Not Find C:\QTProjects\cccc-build-desktop\debug\moc_MainWindow.cpp
    32.  
    33. Could Not Find C:\QTProjects\cccc-build-desktop\ui_MainWindow.h
    34.  
    35. Could Not Find C:\QTProjects\cccc-build-desktop\debug\main.o
    36.  
    37. The process "C:/mingw/bin/mingw32-make.exe" exited normally.
    38. Configuration unchanged, skipping qmake step.
    39. Starting: "C:/mingw/bin/mingw32-make.exe" -w
    40. mingw32-make: Entering directory `C:/QTProjects/cccc-build-desktop'
    41.  
    42. C:/mingw/bin/mingw32-make -f Makefile.Release
    43.  
    44. mingw32-make[1]: Entering directory `C:/QTProjects/cccc-build-desktop'
    45.  
    46. c:\Qt\4.7.2\bin\uic.exe ..\cccc\MainWindow.ui -o ui_MainWindow.h
    47.  
    48. g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Qt\4.7.2\include\QtCore" -I"..\..\Qt\4.7.2\include\QtGui" -I"..\..\Qt\4.7.2\include" -I"..\MyCustomWidget" -I"..\..\Qt\4.7.2\include\ActiveQt" -I"release" -I"." -I"..\cccc" -I"." -I"..\..\Qt\4.7.2\mkspecs\win32-g++" -o release\main.o ..\cccc\main.cpp
    49.  
    50. g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Qt\4.7.2\include\QtCore" -I"..\..\Qt\4.7.2\include\QtGui" -I"..\..\Qt\4.7.2\include" -I"..\MyCustomWidget" -I"..\..\Qt\4.7.2\include\ActiveQt" -I"release" -I"." -I"..\cccc" -I"." -I"..\..\Qt\4.7.2\mkspecs\win32-g++" -o release\MainWindow.o ..\cccc\MainWindow.cpp
    51.  
    52. C:\Qt\4.7.2\bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Qt\4.7.2\include\QtCore" -I"..\..\Qt\4.7.2\include\QtGui" -I"..\..\Qt\4.7.2\include" -I"..\MyCustomWidget" -I"..\..\Qt\4.7.2\include\ActiveQt" -I"release" -I"." -I"..\cccc" -I"." -I"..\..\Qt\4.7.2\mkspecs\win32-g++" -D__GNUC__ -DWIN32 ..\cccc\MainWindow.h -o release\moc_MainWindow.cpp
    53.  
    54. g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Qt\4.7.2\include\QtCore" -I"..\..\Qt\4.7.2\include\QtGui" -I"..\..\Qt\4.7.2\include" -I"..\MyCustomWidget" -I"..\..\Qt\4.7.2\include\ActiveQt" -I"release" -I"." -I"..\cccc" -I"." -I"..\..\Qt\4.7.2\mkspecs\win32-g++" -o release\moc_MainWindow.o release\moc_MainWindow.cpp
    55.  
    56. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows -o release\cccc.exe release/main.o release/MainWindow.o release/moc_MainWindow.o -L"c:\Qt\4.7.2\lib" -lmingw32 -lqtmain C:/QTProjects/MyCustomWidget-build-desktop/release/mycustomwidgetplugin.dll -lQtGui4 -lQtCore4
    57.  
    58. mingw32-make[1]: Leaving directory `C:/QTProjects/cccc-build-desktop'
    59.  
    60. mingw32-make: Leaving directory `C:/QTProjects/cccc-build-desktop'
    61.  
    62. release/MainWindow.o:MainWindow.cpp:(.text$_ZN13Ui_MainWindow7setupUiEP11QMainWindow[Ui_MainWindow::setupUi(QMainWindow*)]+0x129): undefined reference to `MyCustomWidget::MyCustomWidget(QWidget*)'
    63.  
    64. collect2: ld returned 1 exit status
    65.  
    66. mingw32-make[1]: *** [release\cccc.exe] Error 1
    67.  
    68. mingw32-make: *** [release] Error 2
    69.  
    70. The process "C:/mingw/bin/mingw32-make.exe" exited with code %2.
    71. Error while building project cccc (target: Desktop)
    72. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 

    Does this help you locate the problem?

  16. #16
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    The error you posted now is a link error.
    elease/MainWindow.o:MainWindow.cpp.text$_ZN13Ui_MainWindow7setupUiEP11QMainWindow[Ui_MainWindow::setupUi(QMainWindow*)]+0x129): undefined reference to `MyCustomWidget::MyCustomWidget(QWidget*)'
    But error you posted at the beginngin of this thread was a compile error:
    debug/MainWindow.o:C:\QTProjects\cccc-build-desktop/./ui_MainWindow.h:43: undefined reference to `MyCustomWidget::MyCustomWidget(QWidget*)'
    You have to be a bit more cooperative if you want effective help.

    Your link line is not good:
    -L"c:\Qt\4.7.2\lib" -lmingw32 -lqtmain C:/QTProjects/MyCustomWidget-build-desktop/release/mycustomwidgetplugin.dll -lQtGui4 -lQtCore4
    '-l' is missing before 'C:/QTProjects/MyCustomWidget-build-desktop/release/mycustomwidgetplugin.dll'
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  17. #17
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using a custom widget

    Hi
    Sorry if there has been some confusion
    I had already tried '-l'
    It gives this error

    c:/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lC:/QTProjects/MyCustomWidget-build-desktop/release/mycustomwidgetplugin.dll

  18. #18
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    you need to link against the *.lib file not the dll.
    The dll is loaded at runtime.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  19. #19
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using a custom widget

    I don't have a ".lib" file to link against

  20. #20
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: using a custom widget

    Well, you should.
    If you have the custom widget project source, try rebuilding it.
    Without a lib you can't link against this DLL.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Custom GL Widget
    By qtoptus in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2010, 16:28
  2. Replies: 1
    Last Post: 6th May 2010, 10:09
  3. Custom Widget
    By Frej in forum Qt Tools
    Replies: 27
    Last Post: 13th February 2010, 21:13
  4. Replies: 1
    Last Post: 5th November 2006, 23:50
  5. Replies: 9
    Last Post: 8th May 2006, 14:21

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
  •  
Qt is a trademark of The Qt Company.