Qt Creator QuickStart Second Edition main update content

Source: Internet
Author: User
Tags character set
No modifications involving operations or programming are no longer listed.

1th Chapter
1.1.1 Download Software
QT Use 4.8.5 version address: http://download.qt-project.org/official_releases/qt/4.8/4.8.5/ Download file: Qt-win-opensource-4.8.5-mingw.exe qt Creator using 2.8.0 version address: http://download.qt-project.org/official_releases/ qtcreator/2.8/2.8.0/Download File: Qt-creator-windows-opensource-2.8.0.exe

1.1.2 Installing the Software
Install QT Creator first. Double-click Run Qt-creator-windows-opensource-2.8.0.exe, and then follow the default settings (note: If you want to change the installation directory, you cannot have Chinese in the installation path). When the QT Creator installation is complete, double-click Run qt-win-opensource-4.8.5-mingw.exe to install the QT framework. The entire process is also set by default. In the MinGW installation (MinGW installation) interface you need to specify the path to MinGW, which prompts you to use the GCC 4.4 version of MinGW. can go to the Qter Open source Community (www.qter.org) download page download MinGW, download the file is Mingw-gcc440_1.zip, the download will need to unzip it, the author here unzipped to the default installation directory of QT, if this is the default path used , you should fill in the C:\Qt\mingw, as shown in Figure 1-1.

1.2.1 Running a sample program
The QT Creator is now connected to the QT library. Select the tools → options menu item, and then select the build and run item. Because this is the QT and QT Creator that are downloaded and installed separately, they are not automatically associated and need to be set manually by the reader. First set the compiler, click on the upper right corner of the "Add" button, select the first item MinGW, and then add the compiler path, the author here is C:\Qt\mingw\bin\gcc.exe, click on the "Apply" button below to save the settings, as shown in Figure 1-3. Add the Qt version below, click on the "Add" button at the top right, then select the path of Qmake.exe, the author here is C:\Qt\4.8.5\bin\qmake.exe, click "Apply" button once again to save the settings, as shown in Figure 1-4. Finally, in the build kit, you can see that there is already a "desktop (default)", where you can double-click it to set it directly (or add a new suite and set it up), the name can be set at will, and this is changed to "desktop Qt 4.8.5", which indicates QT 4.8.5 Desktop version, the following compiler has the default selection of the previous set of MinGW, and finally the QT version is selected as the previously added Qt 4.8.5 (4.8.5). In order to debug the program later in debug mode, you need to specify the debugger, the reader can go to the Qter Open source Community (www.qter.org) download page to download the debugger, because I am using the Windows 7 operating system, So the downloaded file is Qtcreator-gdb-7.4-mingw32_nt-6.1-i686.tar, the reader can choose to download according to their own system, also can go to Http://download.qt-project.org/official_ releases/gdb/for download. After the download is done, the files need to be decompressed, and the author has extracted it to the C:\Qt directory. Then go back to Qt Creator and continue with the settings, click "Edit ..." after the debugger entry. button to specify the "binary" path in the popup dialog, the author is C:\Qt\qtcreator-gdb-7.4-MINGW32_NT-6.1-i686\gdb-i686-pc-mingw32.exe. The setup is complete as shown in Figure 1-5. Finally click on the "OK" button to save the exit and return to the QT Creator Welcome screen.

2nd Chapter
2.3.1 Pure Code Writing Program and command line compilation

Five, set the display in Chinese. The change code is as follows: 1          #include <QApplication> 2          # Include <QDialog> 3          #include <QLabel> 4      & nbsp   #include <QTextCodec> 5          int main (int argc, char *argv[]) 6  &nbsp ;       {7              qapplication A (argc, argv ); 8              qtextcodec::setcodecfortr (qtextcodec:: Codecforname ("UTF-8")); 9              qdialog W; 10          Qlabel label (&AMP;W); 11          Label.settext (qobject::tr ("Hello world! Hello Qt. ")); 12          w.show (); 13          return a.exec (); 14      }The header file containing the Qtextcodec class was added on line 4th. The Qtextcodec class provides conversion functionality for text encoding. Line 8th uses the static function Setcodecfortr () in the Qtextcodec class to set the character set to be used by the QOBJECT::TR () function, as seen in line 11th, where the TR () function can convert the text encoding using the specified character set. Here, Qtextcodec::codecforname ("UTF-8") is used to specify that the "UTF-8" character set is encoded, and the reader can also set other character sets based on the specific environment. In order to be able to display Chinese, you need to set character sets and then use the QOBJECT::TR () function to encode the strings. In fact, the TR () function can also implement multi-language support, which will be discussed in the 9th chapter of the Internationalization section. It should be explained that the best place to put the SETCODECFORTR () function is in the program, just below the Qapplication object in the main () function. All the strings in the QT program to be displayed to the interface are best enclosed in the TR () function, and if you include Chinese in a string that is not to be displayed on the interface, you can use Qstring () to encode the conversion, which needs to be set in the main function by adding the following code: QTEXTCODEC:: Setcodecforcstrings (Qtextcodec::codecforname ("UTF-8"));         Although using this method can be very simple to achieve the Chinese display, but it is recommended to write code in full use of English, and finally use the 9th chapter on the internationalization of the way to achieve Chinese display.
2.4.2 Project file
        Take a look at the contents of the Helloworld.pro file for the HelloWorld project created in section 2.1:1        &N Bsp #-------------------------------------------------2          # 3          # Project created by Qtcreator 2013-08-07t23:10:24 4          # 5          #-------------------------------------------------6             7          qt      += core GUI 8   & nbsp        9          GreaterThan (qt_major_version,4): QT + = Widgets 10         11       TARGET = HelloWorld 12       TEM PLATE = App 13         14         15     &nbsp ; SOURCES + = main.cpp\ 16               hellodialog.cpp 17         18        headers  += hellodialog.h 19         20        forms    + = Hellodialog.ui 21         22       R c_file  += myico.rc Line 1th to 5th is a comment that describes the time the file was generated. The 7th line shows the module used by this project. The core module contains the central functionality of the QT non-graphical user interface, and all other modules are dependent on this module, while the GUI module expands the graphical interface capabilities of the core module. That is, if you do not need to design a graphical interface of the program, then only the core module is required, but if the graphical interface, then it must include a GUI module. In fact, the so-called module, is a collection of related classes, such as all the graphical interface related classes are in the GUI module, the reader can be in the QT Help to view the Qtcore module and the Qtgui module keyword. Line 9th is to add a line of code that is compatible with QT5, indicating that if it is a Qt5 version, a QT +=widgets line of code is added. Line 11th is the name of the generated target file, which is the name of the generated EXE file, the default is the project name, and of course it can be changed to another name here. Line 12th uses the app template to indicate that this is an application. The 15th, 18, and 20 lines are the source files, header files, and interface files that are included in the project. Line 22nd is the file that adds the application icon. These files all use relative paths, because they are all in the project directory, so only the file names are written.         Here's a reference to the. pro.user file that was generated in the project folder, which contains local build information, including QT version and build directory. You can use Notepad or WordPad to open the file to see its contents. When you use Qtcreator to open a. pro file will automatically generate a. pro.user file. Because the reader's system environment is not the same, Qt installation in the settings are not the same, so if you want to expose their source code, generally do not need to include this user file. If you want to open someone else's project file, but contains the user file, Qt Creator will pop up a prompt window, ask whether to load specific environment settings, you should select "No", and then choose your own Qt version, as shown in Figure 2-30.

3rd Chapter
49th page, modify the description.
Right-click on Showchilddialog and select "Refactor →rename Symbol undercursor" in the pop-up menu, or directly use


5th Chapter
The 103th page. At this point, run the program, and then drag a text file from the desktop into the program. "Add before" finally enter the Mainwindow.cpp file and add Setacceptdrops (True) to the constructor; A line of code that allows the main window to accept the drop event. ”

7th Chapter
1. On page 139th, modify #include<qtcore/qcoreapplication> to: #include <QCoreApplication>
2. On page 141th, modify #include<qtcore/qcoreapplication> to: #include

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.