1. 程式人生 > >QCoreApplication和QApplication的用法及區別

QCoreApplication和QApplication的用法及區別

              一、QCoreApplication用於non-GUI的應用程式(不需要依賴QtGui庫),QApplication用於包含GUI的應用程式(需要用到QtGui庫)。

              二、QApplication繼承了QGuiApplication類,而QGuiApplication繼承了QCoreApplication類,而QCoreApplication又繼承QObject的,而QObject就是QT中最基本的基類,也就是QT的根基。

QCoreApplication和QApplication用法說明:

              QCoreApplication
The QCoreApplication class provides an event loop for console Qt applications.
This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly one QCoreApplication object. For GUI applications, see QApplication.
QCoreApplication contains the main event loop, where all events from the operating system (e.g., timer and network events) and other sources are processed and dispatched. It also handles the application's initialization and finalization, as well as system-wide and application-wide settings.

QApplication
The QApplication class manages the GUI application's control flow and main settings.
QApplication contains the main event loop, where all events from the window system and other sources are processed and dispatched. It also handles the application's initialization, finalization, and provides session management. In addition, QApplication handles most of the system-wide and application-wide settings.
For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any given time. For non-GUI Qt applications, use QCoreApplication instead, as it does not depend on the QtGui library.
The QApplication object is accessible through the instance() function that returns a pointer equivalent to the global qApp pointer.