Slots in derived classes
Thomas Nesges
ThomasNesges at TNT-Computer.de
Sun Dec 12 14:58:06 GMT 1999
Hi,
I wanted to add a slot CurTime() to a QLabel which displays the current
datetime, so I created a new class DateTimeLabel, derived from QLabel.
When I start the small application I get the following errormessage:
QObject::connect: No such slot QLabel::CurTime()
Here's my code:
// Header of DateTimeLabel
#include <qlabel.h>
#include <qdatetime.h>
class DateTimeLabel : public QLabel {
// Q_OBJECT
public:
DateTimeLabel();
~DateTimeLabel();
public slots:
void CurTime();
public:
QDateTime m_CurTime;
};
// Code of DateTimeLabel
#include "datetimelabel.h"
DateTimeLabel::DateTimeLabel()
{
CurTime();
}
DateTimeLabel::~DateTimeLabel()
{
}
// Here's the slots implementation
void DateTimeLabel::CurTime()
{
m_CurTime = QDateTime::currentDateTime();
this->setText(m_CurTime.toString());
}
// main
#include <qapp.h>
#include <qtimer.h>
#include <qlabel.h>
#include <datetimelabel.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
DateTimeLabel *Label = new DateTimeLabel();
Label->setGeometry(100,100,200,20);
app.setMainWidget(Label);
QTimer *timer = new QTimer();
timer->start( 1000, FALSE );
// Here I try to connect timeout() to CurTime()
QObject::connect( timer, SIGNAL(timeout()),
Label, SLOT(CurTime()) );
Label->show();
return app.exec();
}
Ca somebody point me to what I have missunderstood?
Qt documentation says, that every class that uses slots has to 'mention'
Q_OBEJCT in it's definition. If I try to insert it (uncomment it), I get
the followings:
/opt/kde/lib/libkdeui.so: warning: multiple common of `QArrayT<char>
type_info node'
datetimelabel.o: warning: previous common is here
/opt/kde/lib/libkdecore.so: warning: multiple common of `QArrayT<char>
type_info node'
datetimelabel.o: warning: previous common is here
/usr/lib/libqt.so: warning: multiple common of `QArrayT<char> type_info
node'
datetimelabel.o: warning: previous common is here
datetimelabel.o: In function `QArrayT<char> type_info function':
/usr/lib/qt/include/qarray.h(.text+0x19): undefined reference to
`DateTimeLabel::QPaintDevice virtual table'
/usr/lib/qt/include/qarray.h(.text+0x20): undefined reference to
`DateTimeLabel virtual table'
datetimelabel.o: In function `DateTimeLabel::~DateTimeLabel(void)':
/home/thomas/KDevelop/qtclock/qtclock/datetimelabel.cpp:26: undefined
reference to `DateTimeLabel::QPaintDevice virtual table'
/home/thomas/KDevelop/qtclock/qtclock/datetimelabel.cpp:26: undefined
reference to `DateTimeLabel virtual table'
collect2: ld returned 1 exit status
make: *** [qtclock] Error 1
*** Fehler ***
What trys KDevelop to tell me?
TIA Thomas
--
--==[ www.tnt-computer.de ]==--
More information about the KDevelop
mailing list