Linux下Qt Designer 程序设计步骤详解

来源:互联网 发布:前端解析json数组 编辑:程序博客网 时间:2024/06/10 05:49
    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。输入程序:

   #include <QtGui/QApplication>     #include "gotocell.h"        int main(int argc,char *argv[])      {          QApplication a(argc,argv);          gotocell hello;          hello.show();          return a.exec();     } 

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

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


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

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

root@caoyin-Lenovo:/home/caoyin/gotocell# qmake -project
root@caoyin-Lenovo:/home/caoyin/gotocell# qmake
root@caoyin-Lenovo:/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@caoyin-Lenovo:/home/caoyin/gotocell# ./gotocell
就能弹出创建的对话框了

原创粉丝点击