Linux下Qt Designer 程序设计步骤详解
Linux下Qt Designer 程序设计步骤详解
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。输入程序:
- #ifndef GOTOCELL_H #define GOTOCELL_H
- #include <QWidget>
- namespace Ui{
- class Form;
- }
- class gotocell:public QWidget
- {
- Q_OBJECT
- public:
- gotocell(QWidget *parent=0);
- ~gotocell();
- private:
- Ui::Form *ui;
- public slots:
- void on_pushButton_clicked();
- }; // 不能少分号,否则出错
- #endif
3) 新建文件gotocell.cpp。输入程序:
8、生成工程文件,编译并运行,如下:
- #include "gotocell.h"
- #include "ui_gotocell.h"
- gotocell::gotocell(QWidget *parent):
- QWidget(parent),
- ui(new Ui::Form)
- {
- ui->setupUi(this);
- }
- gotocell::~gotocell()
- {
- delete ui;
- }
- void gotocell::on_pushButton_clicked()
- {
- ui->label->setText("helloQT");
- }
root@ www.bkjia.com:/home/caoyin/gotocell# qmake -project
root@ www.bkjia.com:/home/caoyin/gotocell# qmake
root@ www.bkjia.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.bkjia.com:/home/caoyin/gotocell# ./gotocell
就能弹出创建的对话框了
评论暂时关闭