主源文件 ¶
The wizard generates the following code in the main.cpp file:
We will go through the code line by line. The following lines include the header files for the Notepad widget and
QApplication. All Qt classes have a header file named after them.The following line defines the main function that is the entry point for all C and C++ based applications:
The following line creates a
QApplicationobject. This object manages application-wide resources and is necessary to run any Qt program that uses Qt Widgets. It constructs an application object withargccommand line arguments run inargv. (For GUI applications that do not use Qt Widgets, you can useQGuiApplicationinstead.)The following line creates the Notepad object. This is the object for which the wizard created the class and the UI file. The user interface contains visual elements that are called
widgetsin Qt. Examples of widgets are text edits, scroll bars, labels, and radio buttons. A widget can also be a container for other widgets; a dialog or a main application window, for example.The following line shows the Notepad widget on the screen in its own window. Widgets can also function as containers. An example of this is
QMainWindowwhich often contains several types of widgets. Widgets are not visible by default; the functionshow()makes the widget visible.The following line makes the
QApplicationenter its event loop. When a Qt application is running, events are generated and sent to the widgets of the application. Examples of events are mouse presses and key strokes.了解更多
关于
Here
Widget 和窗口几何体
事件和事件处理