QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1835|回复: 4

请教 QT编程问题

[复制链接]
发表于 2005-10-26 10:37:27 | 显示全部楼层 |阅读模式
源代码如下:
#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

请问怎么回事?
 楼主| 发表于 2005-10-26 11:35:49 | 显示全部楼层
代码有问题么?
我的qte是 ./configure -debug -qvfb -depths 4,8,16,32 -keypad-mode -system-jpeg -gif
选择everything
make的
回复

使用道具 举报

发表于 2005-11-3 01:45:36 | 显示全部楼层
不知道你的程序打算做什么
连点介绍都没有么?
回复

使用道具 举报

发表于 2005-11-14 17:23:24 | 显示全部楼层
you can try to split your code into a cpp file and a header file,
and then compile, it will work.
回复

使用道具 举报

发表于 2005-11-21 22:27:36 | 显示全部楼层
[quote:748c5c7684="huales"]you can try to split your code into a cpp file and a header file,
and then compile, it will work.[/quote]

And the reasons...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-23 18:52 , Processed in 0.055690 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表