歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux下Qt Designer 程序設計步驟詳解

Linux下Qt Designer 程序設計步驟詳解

日期:2017/3/1 10:45:56   编辑:Linux編程
1、新建文件夾 gotocell。
2、打開qt designer。點擊“應用程序”-“編程”-“Qt Designer”;或者在終端裡輸入命令:designer。
3、選擇“File”--“New”,選擇“Widget”,然後“Create”。
4、拖入“PushButton” 和“Label”。
5、保存為gotocell.ui ,然後關閉 qt designer 。
6、在gotocell文件夾裡右擊打開終端,輸入命令:uic gotocell.ui -o ui_gotocell.h
7、編寫程序,在gotocell文件夾裡:

1) 新建文件main.cpp。輸入程序:

  1. #include <QtGui/QApplication>
  2. #include "gotocell.h"
  3. int main(int argc,char *argv[])
  4. {
  5. QApplication a(argc,argv);
  6. gotocell hello;
  7. hello.show();
  8. return a.exec();
  9. }

2) 新建文件gotocell.h。輸入程序:

  1. #ifndef GOTOCELL_H #define GOTOCELL_H
  2. #include <QWidget>
  3. namespace Ui{
  4. class Form;
  5. }
  6. class gotocell:public QWidget
  7. {
  8. Q_OBJECT
  9. public:
  10. gotocell(QWidget *parent=0);
  11. ~gotocell();
  12. private:
  13. Ui::Form *ui;
  14. public slots:
  15. void on_pushButton_clicked();
  16. }; // 不能少分號,否則出錯
  17. #endif


3) 新建文件gotocell.cpp。輸入程序:

  1. #include "gotocell.h"
  2. #include "ui_gotocell.h"
  3. gotocell::gotocell(QWidget *parent):
  4. QWidget(parent),
  5. ui(new Ui::Form)
  6. {
  7. ui->setupUi(this);
  8. }
  9. gotocell::~gotocell()
  10. {
  11. delete ui;
  12. }
  13. void gotocell::on_pushButton_clicked()
  14. {
  15. ui->label->setText("helloQT");
  16. }
8、生成工程文件,編譯並運行,如下:

root@ www.linuxidc.com:/home/caoyin/gotocell# qmake -project
root@ www.linuxidc.com:/home/caoyin/gotocell# qmake
root@ www.linuxidc.com:/home/caoyin/gotocell# make
/usr/bin/uic-qt4 gotocelldialog.ui -o ui_gotocelldialog.h
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o gotocelldialog.o gotocelldialog.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp
/usr/bin/moc-qt4 -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. gotocelldialog.h -o moc_gotocelldialog.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o moc_gotocelldialog.o moc_gotocelldialog.cpp
g++ -Wl,-O1 -o gotocell gotocelldialog.o main.o moc_gotocelldialog.o -L/usr/lib -lQtGui -lQtCore -lpthread
root@ www.linuxidc.com:/home/caoyin/gotocell# ./gotocell
就能彈出創建的對話框了
Copyright © Linux教程網 All Rights Reserved