qt初学者 第一个小程序 小界面
生活随笔
收集整理的這篇文章主要介紹了
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生成執行文件
1.6找到QT安裝目錄下的bin文件在路徑上面點擊復制路徑
1.7我的電腦 右擊屬性 高級設置 環境變量 找到path 編輯 添加剛剛的路徑
1.8 運行你的小程序吧
?
?
1.9注意事項
注意你的.cpp文件名要和你創建的 文件夾的名字保持一致 不然編譯會報錯的
總結
以上是生活随笔為你收集整理的qt初学者 第一个小程序 小界面的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 8-15主要复习 1.运算符优先级整体记
- 下一篇: qt creater创建自己的第一个小程