• 4581阅读
  • 2回复

请大牛们帮我看看。。。 [复制链接]

上一主题 下一主题
离线janefei
 
只看楼主 倒序阅读 楼主  发表于: 2009-09-22
刚开始学习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::Layout(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

这应该是基本错误吧,希望大家能帮我解决下,再次谢过。。。


离线rqzrqh

只看该作者 1楼 发表于: 2009-09-22
直接用g++编译肯定是不行的
这种问题最好还是发到QT编程版块
离线浪漫天使
只看该作者 2楼 发表于: 2009-09-23
楼主你贴一下你的pro文件看看
快速回复
限100 字节
 
上一个 下一个