|
源代码如下:
#include <qapplication.h>
#include <qsignalmapper.h>
#include <qstring.h>
#include <qpushbutton.h>
#include <qlayout.h>
class Keypad : public QWidget
{
Q_OBJECT
public:
Keypad(QWidget *parent = 0);
signals:
void digitClicked(int digit);
private:
void createLayout();
QPushButton *buttons[10];
};
Keypad::Keypad(QWidget *parent)
: QWidget(parent)
{
QSignalMapper *signalMapper = new QSignalMapper(this);
connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(digitClicked(int)));
for (int i = 0; i < 10; ++i) {
QString text = QString::number(i);
buttons = new QPushButton(text, this);
signalMapper->setMapping(buttons, i);
connect(buttons, SIGNAL(clicked()), signalMapper, SLOT(map()));
}
createLayout();
}
void Keypad::createLayout()
{
QGridLayout *layout = new QGridLayout(this, 3, 4);
layout->setMargin(6);
layout->setSpacing(6);
for (int i = 0; i < 9; ++i)
layout->addWidget(buttons[i + 1], i / 3, i % 3);
layout->addWidget(buttons[0], 3, 1);
}
int main(int argc,char **argv)
{
QApplication a(argc,argv);
Keypad k;
a.setMainWidget( &k );
k.show();
return a.exec();
}
然后,
qmake -project
qmake
make
编译信息如下:
g++ -c -pipe -Wall -W -O2 -DQT_NO_DEBUG -I/root/Trolltech/qtopia-free-2.1.1-debug/mkspecs/linux-g++ -I. -I. -I/root/Trolltech/qt-2.3.10/include -o mapper.o mapper.cpp
g++ -Wl,-rpath,/root/Trolltech/qt-2.3.10/lib -o mapper mapper.o -L/root/Trolltech/qt-2.3.10/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm
mapper.o(.text+0x1d): In function `Keypad::Keypad[not-in-charge](QWidget*)':
: undefined reference to `vtable for Keypad'
mapper.o(.text+0x23): In function `Keypad::Keypad[not-in-charge](QWidget*)':
: undefined reference to `vtable for Keypad'
mapper.o(.text+0x18d): In function `Keypad::Keypad[in-charge](QWidget*)':
: undefined reference to `vtable for Keypad'
mapper.o(.text+0x193): In function `Keypad::Keypad[in-charge](QWidget*)':
: undefined reference to `vtable for Keypad'
mapper.o(.text+0x3f5): In function `main':
: undefined reference to `vtable for Keypad'
mapper.o(.text+0x3ff): more undefined references to `vtable for Keypad' follow
collect2: ld returned 1 exit status
make: *** [mapper] Error 1
请问怎么回事? |
|