Home

OFF-SOFT.net

OFF-SOFT.net

This site is support & information site of WEB,and Software. This site might help you that create software or Web Site…perhaps?[:]

Qt (3) Check QtDesigner and the ui file

Published on| May 22nd, 2009 | No Comment.
ui files to keep
Finally, let's use it to file ui.

As the diversion created by the class.

  • sample.cpp
    - Main is routine.
  • mainwindow.h
    - QWidget class is inherited header.
  • mainwindow.cpp
    - QWidget inherited class source.

Let's look at the source code.

[mainwindow.h]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QtGui>
 
#ifndef _DEBUG
#pragma comment(lib, "QtUiTools.lib")
#else
#pragma comment(lib, "QtUiToolsd.lib")
#endif
 
class MainWindow : public QWidget
{
	Q_OBJECT
 
public:
	MainWindow();
 
private slots:
    void on_pushButton_clicked();
 
};
#endif
Line 6-10, ui is specified for the class library files.
Already, it is unnecessary to set the library environment are described.

It is, of course, last minute, "Ui:: Form ui;" There was a time, no.

[mainwindow.cpp]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "QMessageBox"
#include "mainwindow.h"
#include "QFile"
#include "QtUiTools/QUiLoader"
 
MainWindow::MainWindow()
{
	QUiLoader oloader;
 
	QFile ofile("test.ui");
	ofile.open(QFile::ReadOnly);
 
	QWidget *widget = oloader.load(&ofile, this);
	ofile.close();
 
	QPushButton* ui_findButton = qFindChild<QPushButton*>(widget, "pushButton");
 
	if(ui_findButton!=NULL){
		connect(ui_findButton, SIGNAL(clicked()), 
		        this, SLOT(on_pushButton_clicked()));
	} else {
		QMessageBox::information (NULL,"Nothing","Nothing pushButton.");
	}
 
    setWindowTitle(tr("SampleWindow"));
 
}
 
void MainWindow::on_pushButton_clicked()
{
	QMessageBox::information (NULL,"Click","Click Click!!");
}
In lines 10-23, ui file, "pushButton" the direct object and click on_pushButton_clicked signal defines a slot.
The course, Auto-onnect, this is not accepted.
※ Auto-onnect: Auto-Connect to conduct a definition of the name only.


[mainwindow.cpp]
1
2
3
4
5
6
7
8
9
10
11
#include <QApplication>
 
#include "mainwindow.h"
 
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    MainWindow mainWin;
    mainWin.show();
    return app.exec();
}

Here, I think the explanation is not required. Create a simple application, just make the screen display.

Now, let's run.
※ test.ui Please copy and run to the same directory as the executable file.

As follows: I think the message box.



I was like. This article is same of more contents of relevant sites . But I changed detail comments and sample source code,because I think you will get more understanding.
Very basic, so it was important, I have ventured to the article.

Related Sites: http://doc.trolltech.com/4.5/designer-using-a-ui-file.html

If you have noticed something, I would appreciate comments.

Comments

Leave a Reply







  • はてなブックマークへ追加する
  • Facebookでシェアする
  • twitter でつぶやく
  • Google Plusでシェアする
  • Pocketでシェアする
ページトップへ