• 8109阅读
  • 2回复

【提问】请教 QT编程问题 [复制链接]

上一主题 下一主题
离线denixleen
 

只看楼主 倒序阅读 楼主  发表于: 2005-10-26
源代码如下:
#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

请问怎么回事? 代码有问题么?
我的qte是 ./configure -debug -qvfb -depths 4,8,16,32 -keypad-mode -system-jpeg -gif
选择everything编译的
[ 此贴被fanyu在2005-10-26 13:56重新编辑 ]
离线hetal

只看该作者 1楼 发表于: 2005-10-26
全都是一个文件???
那肯定错...
离线denixleen

只看该作者 2楼 发表于: 2005-10-26
非常感谢,已经解决,,,,,
快速回复
限100 字节
 
上一个 下一个