Results 1 to 3 of 3

Thread: subclassing QWidget

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    20
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default subclassing QWidget

    Hello,

    it should be really easy but something just doesn't work and i can't find the problem.

    I try to create my own Widget by subclassing QWidget.

    For testing i have now removed every code so that the new Widget looks like this:

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

    and

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

    i would say that there is nothing which could be wrong.

    If i now try to create a instance of this widget in my main application with " SignalWidget sw = new SignalWidget();" i get this error message:

    /usr/include/qt4/QtGui/qwidget.h: In copy constructor ‘SignalWidget::SignalWidget(const SignalWidget&)’:
    /usr/include/qt4/QtGui/qwidget.h:746: error: ‘QWidget::QWidget(const QWidget&)’ is private
    src/signalwidget.h:8: error: within this context
    src/robotcontrol.cpp: In constructor ‘RobotControl::RobotControl(QWidget*)â€℠¢:
    src/robotcontrol.cpp:14: note: synthesized method ‘SignalWidget::SignalWidget(const SignalWidget&)’ first required here
    src/robotcontrol.cpp:14: error: initializing temporary from result of ‘SignalWidget::SignalWidget(QWidget*)â€℠¢
    make: *** [robotcontrol.o] Error 1
    Does someone has an idea what's wrong?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: subclassing QWidget

    Qt Code:
    1. SignalWidget *sw = new SignalWidget();
    To copy to clipboard, switch view to plain text mode 
    Notice the *. and clean up your directory and rerun qmake and make. Maybe it is caused by old object files.

    EDIT: and without Q_OBJECT your example code will work.
    EDIT2: Its definitely to late for me! Is a moc-file generated? Sometimes it comes to problems if all is one file...
    Last edited by Lykurg; 23rd February 2009 at 20:34.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    20
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: subclassing QWidget

    Thanks! The missing "*" solved all problems!

    Damn, i just shouldn't sit that long in front of the computer...

Similar Threads

  1. QtScript Binding problem with QWidget
    By zack in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 09:38
  2. Replies: 0
    Last Post: 11th November 2008, 15:36
  3. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  4. Error in put one QWidget in another QWidget
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 16:05
  5. Replies: 3
    Last Post: 8th March 2007, 14:54

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.