Introduction to Qt creator
Through the previous "QT QuickStart (Vim Pure Code writing)" Learning that only set up the QT environment (QT Library and development tools ), you can use vim pure code to write QT program, and then use QT qmake tools to compile QT code, the specific process is as follows:
1) Write Qt code
2) generate project files via qmake-project
3" project file: QT + = widgets
5" to generate the required executable program by make compiled code
6) through " ./ Run program
However, if the QT program is relatively large, through the above way to write more cumbersome (greatly affect the writing efficiency), next to introduce you to a QT integrated development environment (IDE)--QT Creator, using QT Creator can Complete Qt development tasks more quickly and easily . What we need to note here is thatQT Creator only assists us in the rapid development of QT programs, not that the development of QT program is not to qt Creator .
Qt Creator is a new cross-platform QT IDE (integrated development environment) that can be used alone or with the QT Library and development tools to form a complete SDK (software Development Kit). These include: Advanced C + + code Editor, project and build management tools, integrated context-sensitive Help system, graphical debugger, code management and browsing tools.
The following example is tested in Ubuntu environment, because QT and QT Creator have cross-platform features , so if Windows also installed QT Creator (see "QT 5.5.0 Windows Environment Building"), in The QT code written under Ubuntu can be completely unmodified, that is, the QT Creator compilation runs in Windows. Similarly, the code that is written in Windows can be compiled and run under Ubuntu, so choose your own platform.
The following is the Qt Creator interface diagram, different versions vary (not very small):
1) Welcome mode (Welcome): Here you can choose to bring your own example to show that the next time you open the Welcome screen, you will be able to display some of the most recent items.
2) compilation mode (Edit): Write code here for programming.
3)Designer mode (design): A graphical interface is designed here to perform such operations as part property setting, signal and slot setting, and layout setting.
4) Debugmode (Debug): In this interface you can debug the program as needed in order to track the operation of the Watcher.
5) Project Setup (Projects): This interface allows you to complete the configuration of the development environment.
6) help mode: You can enter keywords here to find relevant information.
Create a blank project
Sometimes, if we use someone else's well-written QT code, this code may not include the project file (sample code download please click this link: Http://download.csdn.net/detail/tennysonsky), at this time, we need to use QT Creator Create a blank project file and add the required information.
1) Right-click File--New file or project
2) Other projects, Empty Qmake project
3) Fill in the project name and choose the storage path. The new project automatically creates a folder with a. Pro project file with the same name as the folder.
4) Next
5) Complete
6) in edit mode, select the project directory right click, "Add Existing File", add the required files (mainly. cpp and. h files)
7) In the edit mode, add the corresponding module information in the project file, for example:QT + = Widgets
8) After saving the compilation run, select the project directory right click, "Run", you can compile and run the program
Qt Creator Regardless of the way in which the project files are created, the directory where the project files are located automatically generates a user profile with the suffix. Username, which mainly holds the configuration information for this project (e.g., the path to the project, some error messages when compiling the code), so If you want to copy the code you write to others to use, it is best to delete this configuration file .
Let's teach you how to quickly open the directory where the project is located:
Select "Show included Directories" in edit mode, select Project file, right click, to display the directory where the project is located (this method can also open the directory where the code file is located):
after the QT code is run by Qt Creator, a matching buid-directory is generated in the catalog's sibling directory :
enter this build-directory to find executable programs that can be run directly through "./" at the terminal :
Build Gui Application complete ProjectCreate a complete project (without UI)
Next, we create a Gui application complete project (without the UI, as for what the UI, described later), we can create a blank window without writing a line of code at all.
1) Right-click File--New file or project
2) application, Qt Widgets application
3) Fill in the project name and select the storage path
4) Next
5) Fill in the class name of the custom class, select the desired base class (Qmainwindow, Qwidget, Qdialog), where the base class is selected as qwidget. By default, the Create Interface check box is selected to indicate that you need to design the interface with your own interface designer, otherwise you need to use the code to complete the design of the interface, which is not selected here .
The Qmainwindow class provides a main application window with a menu bar, an anchor window (such as a toolbar), and a status bar.
The Qwidget class is the base class for all user-interface objects.
The Qdialog class is the base class for dialog Windows. A dialog window is a top-level window that is primarily used for short-term tasks and for brief communication with users.
6) Complete
7) Compile and run the program, click the green right arrow in the lower left corner, or press the shortcut key "Ctrl + R" to run the result as a blank window.
We did not write a single line of code to create a blank window, if you want to add a button on the window, you need to create a button object in the. h file custom class, corresponding to the. cpp file constructor, the corresponding property settings for the button, the specific operation and "QT QuickStart (Vim Pure Code writing)" the same.
Here are some common shortcut keys:
1) Help file:F1 (cursor on the function name or class name, press F1 to jump to the corresponding help document to see its detailed usage)
2). h file and corresponding . cpp file switch:F4
3) Compile and run:Ctrl + R
4) function declaration and definition switch:F2
5) Code comment uncomment:Ctrl +/ (check the code and press the shortcut key again)
6) font size becomes smaller:Ctrl + mouse wheel up and down
Create a complete project (with UI)
Operation and creation of a complete project (without UI) is basically the same, the main difference is that in the fifth step, the default is to Select the "Create Interface" check box, indicating the need to use the interface designer to design the interface, otherwise you need to use the code to complete the design of the interface , which is selected by default .
Next, you can find that the code directory structure is more than one interface file column: Mywidget.ui, which is the UI file (interface file), this file is actually an XML file.
Double-click the UI file to enter design mode, and go to the designer QT designer editing state to begin the design (QT designer) programming .
In the process of QT program development, the process of software development through handwritten code, but also through the Qt interface designer (QT Designer) interface drawing and layout . The interface designer (QT Designer) provides QT basic drawing widgets, which can be dragged and dragged through the mouse directly in the designer, enabling the design of graphical interfaces efficiently and quickly, with an intuitive interface and WYSIWYG. This has the advantage of being able to visually see the components on the interface at the same time, and to adjust the design of the interface at any time.
To add the required widgets to the UI:
Set the part properties as needed:
Qt Designer Most of the operations are similar, need their own multi-operation, multi-validation, here is not an example of the explanation.
after you have set up the graphical interface through Qt Designer, you can compile and run the program, the same steps as before .
If the program has been compiled, not modified to compile, the program will no longer perform the compilation process, immediately run. If the program does not modify and you want to perform the compilation action, you need to clear and then compile the run:
1) Set mode switch to edit mode
2. In edit mode, select the project directory, right-click, clear, run
When the program compiles, it can see its corresponding compilation information through the "4 compile output" in the bottom of the interface:
If the program runs successfully, "3 application Output" will be viewed at the bottom of the interface to see the program output status, and if the program has a print operation, print information will be output here:
If there is a problem with the program code, compile error, the interface at the bottom of the "1 problem" input error message, double-click the information to jump to the error code:
Copyright NOTICE: This blog post, mostly I compiled, or in the network collection, reproduced please indicate the source!!
The use of Qt introductory learning--QT Creator