吾闻池中鱼,不识海水深。
相互间的继承关系: QApplication <—— QGuiApplication <—— QCoreApplication <—— QObject
Qt模块:
QCoreApplication定义在core模块中,为应用程序提供了一个非gui的事件循环;QGuiApplication定义在gui模块中,提供了额外的gui相关的设置,比如桌面设置,风格,字体,调色板,剪切板,光标;QApplication定义在widgets模块中,是QWidget相关的,能设置双击间隔,按键间隔,拖拽距离和时间,滚轮滚动行数等,能获取桌面,激活的窗口,模式控件,弹跳控件等。
如果你的应用程序是无界面的,直接使用QCoreApplication即可,如果是gui相关,但没有使用widgets模块的就使用QGuiApplication,否则使用QApplication。
“QApplication specializes QGuiApplication with some functionality needed for QWidget-based applications. It handles widget specific initialization, finalization.”
没有界面的Qt程序建议使用QCoreApplication:
Some GUI applications provide a special batch mode ie. provide command line arguments for executing tasks without manual intervention. In such non-GUI mode, it is often sufficient to instantiate a plain QCoreApplication to avoid unnecessarily initializing resources needed for a graphical user interface. The following example shows how to dynamically create an appropriate type of application instance:
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();
}
Ref:
https://blog.csdn.net/jigetage/article/details/84878909