Results 1 to 20 of 26

Thread: using a custom widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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!

  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

    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.

  3. #3
    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 

  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

    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.

  5. #5
    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

  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

    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.

  7. #7
    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?

  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

    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.

  9. #9
    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

  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

    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.

  11. #11
    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

  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

    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.