免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2674 | 回复: 1
打印 上一主题 下一主题

《linux程序设计3》中第17章的Qt问题?? 新手不懂啊!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-11 23:26 |只看该作者 |倒序浏览
问题主要有两个:
  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();
}

论坛徽章:
0
2 [报告]
发表于 2008-01-12 10:36 |只看该作者
晕!! 不好意思!!

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

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

第一个问题大家看看吧!!
要是还和第二个一样没含量,大家就骂我,不过一定要帮忙看看
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP