I have been studying QT for a while. Today I am pleasantly surprised to get a book. It's time to record your QT learning path. I haven't written a blog for a long time ~~ Learning is still very important.
Environment: qt sdk 1.1.3 QT version 4.7.3
At present, I am not very familiar with QT and will introduce some details later.
EachProgramThe beginning is "Hello World", and we are no exception here.
The main interface after QT creator is started is as follows:
1,
2. select a new file or project in the file. The next step is to name the project name. Note that the project path of QT cannot contain Chinese characters.
3. Next we can set the class information. We can create a C ++ class based on a certain base class. We can also choose to create the interface. The system will create a *. UI file. We can also create an empty QT project, and then add a main. cpp. The following program creates an empty QT project.
4. Let's enter it in Main. cpp.Code
# Include <qtgui> int main (INT argc, char * argv []) {qapplication A (argc, argv); qwidget * pwidget = new qwidget; // create a new widget qlabel label (pwidget); // label's parent is pwidget // qlabel * label = new qlabel (pwidget); label. settext (qobject: TR ("Hello World"); // set the label text pwidget-> show (); // show the pwidget return a.exe C ();}
5. After the program is executed
6. Let's analyze the above program
The first line contains the header file. I often directly include qtgui. We can open qtgui and find that it contains header files of many modules. Qtgui defines the graphical user interface class
Another important header file is qtcore, which is the basic module of qt4 and defines the non-Gui class of the QT core used by other modules.
Qapplication A (argc, argv );
Create a qapplication object and pass the parameters entered in the console to the application object. Any GUI program designed using QT must contain a qapplication object.
Qwidget * pwidget = new qwidget;
Here we create a widget.
This section describes the concepts of windows and widgets.
Window: a graphic user interface is called a window. It usually has a title bar, window border, and can be dragged and changed by the mouse (such as a dialog box ).
Widget: it is a general term for all graphic user interfaces. It can appear either as a separate window or inside a window (such as a tag)
Qlabel label (pwidget); label. settext (qobject: TR ("Hello World "));
Create a tag, specify its parent window as pwidget, and set the text contentHelloWorld
Pwidget-> show ();
Finally, we can display pwidget.
The execution of the qapplication: exec () Statement enables the qtgui to enter a main event loop until exit (), quit (), or the main window of the application is closed. After the main event cycle starts, it receives user interface events and events from other event sources, and distributes and processes the events to corresponding windows. In addition, it completes the initialization of the QT application and the aftercare after the application program runs, and provides session management)
7. Use Chinese characters in the program
If the program needs to use Chinese characters, we must add them to main. cpp.
Qtextcodec: setcodecfortr (qtextcodec: codecforlocale ());
Or
Qtextcodec: setcodecfortr (qtextcodec: codecforname ("gb18030 "));
// The Character Set gb18030 is a national standard
Otherwise, garbled characters are displayed in Chinese on the interface.
There are many ways to make QT programs use Chinese.
Add the program hereSource codeDownload link: http://download.csdn.net/detail/fzu_dianzi/3702965
the above are purely personal study notes. If anything is wrong, I hope to raise it. We hope to study and make progress together. My email address is: xzy@yingzhi8.com