• 5095阅读
  • 2回复

《linux程序设计3》中第17章的Qt问题?? [复制链接]

上一主题 下一主题
离线ztianshan
 

只看楼主 倒序阅读 楼主  发表于: 2008-01-11
— 本帖被 XChinux 执行加亮操作(2008-07-17) —
问题主要有两个:
  1:在ButtonWindow例中 通过书中写的编译方式:
        g++ -o button ButtonWindow.cpp -I$QTDIR/include -L$QTDIR/lib -lqt
    总是会有以下错误提示:
    /tmp/cc8kmfNl.o: In function `ButtonWindow::~ButtonWindow()':
ButtonWindow.cpp:(.text+0x95): undefined reference to `vtable for ButtonWindow'
ButtonWindow.cpp:(.text+0x9f): undefined reference to `vtable for ButtonWindow'
/tmp/cc8kmfNl.o: In function `ButtonWindow::~ButtonWindow()':
ButtonWindow.cpp:(.text+0xd1): undefined reference to `vtable for ButtonWindow'
ButtonWindow.cpp:(.text+0xdb): undefined reference to `vtable for ButtonWindow'
/tmp/cc8kmfNl.o: In function `ButtonWindow::~ButtonWindow()':
ButtonWindow.cpp:(.text+0x10d): undefined reference to `vtable for ButtonWindow'
/tmp/cc8kmfNl.o:ButtonWindow.cpp:(.text+0x117): more undefined references to `vtable for ButtonWindow' follow
collect2: ld returned 1 exit status
 
  2:于是我只好通过qmake编译,结果编译出来的程序  点击"click me" 按钮后 在terminal中不会像书中提到的那样打印出:"clicked" 字样!!

请问这是怎么回事,大家帮忙解决一下把!!!!!!



程序源码如下:

ButtonWindow.h:

#include<qmainwindow.h>

class ButtonWindow : public QMainWindow
{
    Q_OBJECT
   
    public:
        ButtonWindow(QWidget *parent = 0, const char *name = 0);
        virtual ~ButtonWindow();

    private slots:
        void Clicked();
};




ButtonWindow.cpp:

#include"ButtonWindow.h"
#include<qpushbutton.h>
#include<qapplication.h>
#include<iostream.h>

ButtonWindow::ButtonWindow(QWidget *parent, const char *name) : QMainWindow(parent, name)
{
    this->setCaption("This is the window Title");
    QPushButton *button = new QPushButton("Click Me!", this, "stuff");
    button->setGeometry(50, 30, 70, 20);
    connect(button, SIGNAL(clicked()), this, SLOT(Clicked));
}

ButtonWindow::~ButtonWindow()
{
}

void ButtonWindow::Clicked(void)
{
    cout<<"clicked!\n";  //为什么不会打印出来???
}

int main(int argc, char **argv)
{   
   
    QApplication app(argc, argv);
    ButtonWindow *window = new ButtonWindow();

    app.setMainWidget(window);
    window->show();

    return app.exec();
}
离线ztianshan

只看该作者 1楼 发表于: 2008-01-12
  晕!! 不好意思!! 

第二个问题解决了  Clicked后忘写“()”啦!!

可是为什么编译时不会有 错误提示呢???

第一个问题大家看看吧!!
要是还和第二个一样没含量,大家就骂我,不过一定要帮忙看看
离线youngst

只看该作者 2楼 发表于: 2008-01-16
第一个问题,你有自定义slot,所以需要moc_ButtonWindow.cpp  ,不然编译会报错的, 你使用qmake后,在Makefile,他会有通过moc 生成moc_XX.cpp.链接moc_xx.o等一些 编译的过程,就不会报错.
快速回复
限100 字节
 
上一个 下一个