Qt学习笔记(二)——qt空文档项目

/////////////2015/08/07///////////////

////////////by xbw//////////////////////

///////////环境 Qt 5.3.1////////////

学习的视频是QT4,多少有点问题,我用的QT5,在这个空文档项目中发现了问题,

在main.cpp中的头文件没有文件或目录,经过网上查找,发现QT升级5后的GUI归到Widget中了,所以呢,在5中我们就需要在pro中加上这么一句QT+= coregui widgets就好了

#include 
#include 
#include 
#include 
#include 
#include 
#include 
int main(int argc,char *argv[])
{
    QApplication app(argc,argv);
    QWidget *window1=new QWidget;
    window1->setWindowTitle("My App");

    QGridLayout *layout=new QGridLayout;
    QLabel *label1 =new QLabel("Name:");
    layout->addWidget(label1,0,0);
    window1->show();

    //创建一个窗口
    QWidget *window=new QWidget;
    //窗口名字
    window->setWindowTitle("My App");
    //创建三个按钮
    QPushButton *button1=new QPushButton("one");
    QPushButton *button2=new QPushButton("one");
    QPushButton *button3=new QPushButton("one");
    //一个水平排列指针
    QHBoxLayout *hlayout =new QHBoxLayout;
    //水平排列指针指向三个按钮
    hlayout->addWidget(button1);
    hlayout->addWidget(button2);
    hlayout->addWidget(button3);

    window->setLayout(hlayout);
    window->show();
    //创建一个显示文本窗口
    QLabel *label=new QLabel("

Hello

Hello world"); label->show(); return app.exec(); }



你可能感兴趣的:(QT)