PDA

View Full Version : subclassing QWidget



BeS
23rd February 2009, 19:12
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:



#ifndef SIGNALWIDGET
#define SIGNALWIDGET

#include <QtGui>
#include <QWidget>

class SignalWidget : public QWidget
{
Q_OBJECT

public:
SignalWidget(QWidget *parent = 0);
};

#endif


and



#include "signalwidget.h"


SignalWidget::SignalWidget(QWidget *parent)
: QWidget(parent)
{
}


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!

Lykurg
23rd February 2009, 20:15
SignalWidget *sw = new SignalWidget();
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...

BeS
23rd February 2009, 20:38
Thanks! The missing "*" solved all problems!

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