- 论坛徽章:
- 0
|
问题主要有两个:
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();
} |
|