|
请大牛们帮我看看。。。
刚开始学习Qt, 模仿着编写了一个程序,但是出现了错误,希望好心人帮我看看,指点指点,呵呵。。。
程序代码为:
先定义了一个头文件:Layout.h
#include <qmainwindow.h>
#include <qstring.h>
class Layout : public QMainWindow
{
Q_OBJECT
public:
Layout(QWidget *parent = 0, const char *name = 0);
private slots:
void Clicked();
};
Layout类的实现如下:Layout.cpp
#include "Layout.h"
#include <qpushbutton.h>
#include <qapplication.h>
#include <qlistbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <iostream.h>
Layout:ayout(QWIdget *parent, const char *name) : QMainWindow(parent, name)
{
QWidget *widget = new QWidget(this);
setCentralWidget(widget);
QVBoxLayout *buttonBox = new QVBoxLayout(widget, 1, 6, "bottonBox");
QPushButton *button = new QPushButton("Cancel", this);
buttonBox->addWidget(new QPushButton("OK", this));
buttonBox->addWidget(button);
buttonBox->addStretch(1);
buttonBox->addWidget(new QPushButton("Help", this));
connect(button, SIGNAL(clicked()), this, SLOT(Clicked()));
QListBox *countryList = new QListBox(this);
countryList->insertItem("Canada");
countryList->insertItem("China");
countryList->insertItem("USA");
QHBoxLayout *middleBox = new QHBoxLayout(11);
middleBox ->addWidget(countryList);
middleBox ->addLayout(buttonbox);
QVBoxLayout *topLevelBox = new QVBoxLayout(this, 6, 11);
topLevelBox -> addWidget(new QLabel("select a country", this))
topLevelBox->addLayout(middleBox);
}
void Layout::Clicked(void)
{
std::cout<<"you want to cancel"<<endl;
}
主函数:main.cpp
#include <qpushbutton.h>
#include <qapplication.h>
#include <qlistbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <iostream.h>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Layout *layout = new Layout();
app.setMainWidget(layout);
layout->show();
return app.exec();
}
我make之后出现的错误为:
g++ -o Layout -L/usr/lib/qt-3.3/lib -lqt-mt -lXext -lX11 -lm
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld 返回 1
make: *** [Layout] 错误 1
这应该是基本错误吧,希望大家能帮我解决下,再次谢过。。。 |
|