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

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.