QCoreApplication总览:
The QCoreApplication class provides an event loop for Qt applications without UI
Properties
一些有关程序的名称:
applicationName : QString
applicationVersion : QString
organizationDomain : QString
Public Functions
除了和事件处理有关,主要是权限
checkPermission(const QPermission &permission)-(since 6.5)
Qt::PermissionStatus
requestPermission(const QPermission &permission, Functor &&functor)-void
关于Permision:
e.g:
qApp->checkPermission(QCameraPermission{});
这些是子类
在此类中控制了事件循环和事件处理:
The event loop is started with a call to exec().exec() will not return until the event loop exits; e.g., when quit() is called.
QGuiApplication:
The QGuiApplication class manages the GUI application's control flow and main settings
文档不推荐此类:For non-GUI Qt applications, use QCoreApplication instead, as it does not depend on the Qt GUI module. For QWidget based Qt applications, use QApplication instead, as it provides some functionality needed for creating QWidget instances.
It initializes the application with the user's desktop settings, such as palette(), font() and styleHints(). It keeps track of these properties in case the user changes the desktop globally, for example, through some kind of control panel.
It performs event handling, meaning that it receives events from the underlying window system and dispatches them to the relevant widgets. You can send your own events to windows by using sendEvent() and postEvent().
It parses common command line arguments and sets its internal state accordingly. See the constructor documentation below for more details.
It provides localization of strings that are visible to the user via translate().
It provides some magical objects like the clipboard().
It knows about the application's windows. You can ask which window is at a certain position using topLevelAt(), get a list of topLevelWindows(), etc.
It manages the application's mouse cursor handling, see setOverrideCursor()
It provides support for sophisticated session management. This makes it possible for applications to terminate gracefully when the user logs out, to cancel a shutdown process if termination isn't possible and even to preserve the entire application's state for a future session. See isSessionRestored(), sessionId() and commitDataRequest() and saveStateRequest() for details.
QApplication:
GuiApp的子类,添加了对css的支持与widgets的管理
QApplication specializes QGuiApplication with some functionality needed for QWidget-based applications. It handles widget specific initialization, finalization.
Doc中建议这么写:
QCoreApplication* createApplication(int &argc, char *argv[])
{
for (int i = 1; i < argc; ++i) {
if (!qstrcmp(argv[i], "-no-gui"))
return new QCoreApplication(argc, argv);
}
return new QApplication(argc, argv);
}
int main(int argc, char* argv[])
{
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
if (qobject_cast<QApplication *>(app.data())) {
// start GUI version...
} else {
// start non-GUI version...
}
return app->exec();
}
评论区