After Qt is installed, enter the first step $ designer # in the Shell to bring up the designer. The second step window design work form is HelloDialog. Save the form as hellodialog. ui under the Hello directory. Step 3: Create a new main. cpp file under the Hello directory for ui calls by the source program, # include & lt; QApplication & gt; & nbsp
After Qt is installed, you can enter
Step 1 $ designer # Bring up the designer
Step 2: design the window
The form is HelloDialog. Save the form as hellodialog. ui under the Hello directory.
Step 3: Call the ui by the source program
Create a new main. cpp file in the Hello directory,
- # Include
- # Include
- # Include "ui_hellodialog.h"
- IntMain (IntArgc,Char* Argv [])
- {
- QApplication app (argc, argv );
- Ui: HelloDialog ui;
- QDialog * dialog =NewQDialog;
- Ui. setupUi (dialog );
- Dialog-> show ();
- ReturnApp.exe c ();
- }
Step 4 $ qmake-project # generate the pro File
Shell enters the hello directory,
$ Qmake-project # generate hello. pro
Step 5 $ qmake-hello. pro generate the makefile file
$ Qmake-hello. pro # generate the makefile file
The qmake tool is very intelligent. It can automatically detect the user interface file hellodialog. ui and generate appropriate makefile rules to call the user interface compiler (uic) of Qt ).
The uic tool converts the hellodialog. ui file to C ++ and stores the conversion result in the ui_hellodialog.h file.
The generated ui_hellodialog.h file contains the definition of the class Ui: HelloDialog, which is a c ++ file equivalent to hellodialog. ui. This class declares some member variables, stores the child widgets and la s in the form, www.linuxidc.com, and setupUi () functions used to initialize the form. The generated classes are as follows:
- Class Ui: HelloDialog
- {
- Public:
- QLabel * label;
- QLineEdit * lineEdit;
- QSpacerItem * spacerItem;
- QPushButton * okButton;
- ....
- Void setupUi (QWidget * widget ){
- ...
- }
- };
The generated class does not have any base class. when calling the form in main, you can create a QDialog object and pass it to the setupUi () function.
Step 6 $ make # generate a hello program in the current directory
Step 7 $./hello # Run the hello program
$ Qtdemo view the qt demo program
$ Assistant open the qt document
$ Make: Compile qt, generate the qt library, and compile all the demo programs, sample programs, and tool software. In some systems, gmake commands are generated.
The built-in qt compilation tool is qmake. Open-source IDE software includes KDevelop and QDevelop. I installed QDevelop here. They are all written in Qt and provide good support for Qt development.
Qmake can generate makefile related to the platform using the. pro file unrelated to the platform.
Three types of project files: app (separate application), lib (static and dynamic library), and subdirs (recursive compilation). The project file type is specified using the TEMPLATE variable.
TEMPLATE = lib
The subdirs template can be used to compile the target file in the subdirectory. In addition to TEMPLATE = subdirs, you must specify the SUBDIRS variable. In each subdirectory, qmake searches for the. pro file named after the directory name and compiles the project.
To generate the makefile of the project file hello. pro, enter qmake hello. pro,
You can call make or nmake to compile the project.
You can also use the-project parameter to generate the. pro file using qmake in the current directory,
E.g. qmake-project
In this mode, qmake searches for files with known extensions (. h.,. cpp,. ui, and so on) in the current directory and generates a. pro file listing these files.