Qt development in Ubuntu

Source: Internet
Author: User
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,

  1. # Include
  2. # Include
  3. # Include "ui_hellodialog.h"
  4. IntMain (IntArgc,Char* Argv [])
  5. {
  6. QApplication app (argc, argv );
  7. Ui: HelloDialog ui;
  8. QDialog * dialog =NewQDialog;
  9. Ui. setupUi (dialog );
  10. Dialog-> show ();
  11. ReturnApp.exe c ();
  12. }

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:

  1. Class Ui: HelloDialog
  2. {
  3. Public:
  4. QLabel * label;
  5. QLineEdit * lineEdit;
  6. QSpacerItem * spacerItem;
  7. QPushButton * okButton;
  8. ....
  9. Void setupUi (QWidget * widget ){
  10. ...
  11. }
  12. };

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.