qt初学者 第一个小程序 小界面

//标签 \ q push button \ 文本编辑框 || qmake -project 生成工程文件 (.pro    对工程文件修改 最后加上 QT += widgets gui || qmake || mingw32-make
#include <QApplication>

#include <QLabel>
#include <QLineEdit>
#include <QPushButton>

#include <QHBoxLayout>

#include <QVBoxLayout>

#include <QWidget>


int main(int argc , char *argv[])
{
    QApplication app(argc,argv);        //创建一个程序对象

    QLabel *infoLabel = new QLabel;
    QLabel *openLabel = new QLabel;

    QLineEdit *cmdQLineEdit = new QLineEdit;

    QPushButton *commitbutton = new QPushButton;
    QPushButton *cancelbutton = new QPushButton;
    QPushButton *browsebutton = new QPushButton;

    infoLabel->setText("please input message :");
    openLabel->setText("open ");

    cmdQLineEdit->clear();

    commitbutton->setText("commit");
    cancelbutton->setText("cancel");
    browsebutton->setText("browse");

    QHBoxLayout *cmdQHBoxLayout = new QHBoxLayout;
    cmdQHBoxLayout->addWidget(openLabel);
    cmdQHBoxLayout->addWidget(cmdQLineEdit);

    QHBoxLayout *buttonQHBoxLayout = new QHBoxLayout;
    buttonQHBoxLayout->addWidget(commitbutton);
    buttonQHBoxLayout->addWidget(cancelbutton);
    buttonQHBoxLayout->addWidget(browsebutton);


    QVBoxLayout *mainQVBoxLayout = new QVBoxLayout;
    mainQVBoxLayout->addWidget(infoLabel);
    mainQVBoxLayout->addLayout(cmdQHBoxLayout);
    mainQVBoxLayout->addLayout(buttonQHBoxLayout);

    QWidget *w = new QWidget;
    w->setLayout(mainQVBoxLayout);

    w->show();

    return app.exec();            //不能让程序死了 死循环
}

1.1打开qt

1.2进入你创建的qt工程文件目录

1.3生成工程文件

1.3.1打开生成的工程文件 最后加上QT += widgets gui

1.4编译

1.5生成执行文件

扫描二维码关注公众号,回复: 2795783 查看本文章

1.6找到QT安装目录下的bin文件在路径上面点击复制路径

1.7我的电脑 右击属性 高级设置 环境变量 找到path 编辑 添加刚刚的路径

1.8 运行你的小程序吧
 

1.9注意事项

注意你的.cpp文件名要和你创建的 文件夹的名字保持一致 不然编译会报错的

猜你喜欢

转载自blog.csdn.net/qq_38313246/article/details/81737911