概述
//标签 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生成执行文件
1.6找到QT安装目录下的bin文件在路径上面点击复制路径
1.7我的电脑 右击属性 高级设置 环境变量 找到path 编辑 添加刚刚的路径
1.8 运行你的小程序吧
1.9注意事项
注意你的.cpp文件名要和你创建的 文件夹的名字保持一致 不然编译会报错的
最后
以上就是贪玩戒指为你收集整理的qt初学者 第一个小程序 小界面的全部内容,希望文章能够帮你解决qt初学者 第一个小程序 小界面所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复