- 论坛徽章:
- 0
|
The techniques of using qt4-designer
This is my gained knowledge,I would like to share with all of you.
1.create .ui file,this file contain many GUI components,for example you create a dialog class called "DisplayDialog",and
added other widgets on it.And every one you all rename it.
(We assume this .ui file was sorted as name "displaydialog.ui")
We add a PushButton and a LineEdit on the main widget,set their property as follow:
QPushButton:exitButton
QLineEdit:lineEdit
Connect the signal "clicked()" of "exitButton" to the slot "accept()" of "DisplayDialog".
2.We declare a new class inherited from "DisplayDialog" designed in above .ui file.The common style as follow:
(Attention:A new file will be created automatically by qmake tool,so we include the .ui file,we should add "ui_" at the
front of the file name,)
//displaydialog.h
#ifndef DISPLAYDIALOG_H
#define DISPLAYDIALOG_H
#include
#include "ui_displaydialog.h" //the file will be created automatically by qmake
class DispDialog:public QDialog,public Ui::DisplayDialog //inherit from Ui
{
Q_OBJECT
public:
DispDialog(QWidget *parent=0);
void setLineEditContent(QString &text);
};
3.We implement the source code in displaydialog.cpp file.
//displaydialog.cpp
#include
#include "displaydialog.h"
DispDialog::DispDialog(QWidget *parent):QDialog(parent)
{
setupUi(this);
QString tip("creatory has been succeed");
this->setLinEditContent(tip);
}
void DispDialog::setLineEditContent(QString &text);
{
lineEdit->setText(text);
}
4.The next step is to create our main.cpp file
#include
#include "displaydialog.h"
int main(int argc,char **argv)
{
QApplication app(argc,argv);
DispDialog *dialog=new DispDialog;
dialog->show();
return app.exec();
}
4.Ok,now let's to complie our application,it's so easy,thanks to qmake tools.
qmake -project
qmake
make
The remain question:
What's the funtion of the following segment:
setupUi(this);
???????????
If you know how it works ,please contact me at :creatory@163.com,Thank you!
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/56374/showart_520661.html |
|