QApplication docs: restore console mode -snippet
Change-Id: I1f8ce949ae660a209a2092a2863d5c25e2908004 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
This commit is contained in:
parent
a31dd2e995
commit
e481ea595e
@ -39,23 +39,25 @@
|
||||
****************************************************************************/
|
||||
|
||||
//! [0]
|
||||
int main(int argc, char **argv)
|
||||
QCoreApplication* createApplication(int &argc, char *argv[])
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
bool useGUI = getenv("DISPLAY") != 0;
|
||||
#else
|
||||
bool useGUI = true;
|
||||
#endif
|
||||
QApplication app(argc, argv, useGUI);
|
||||
for (int i = 1; i < argc; ++i)
|
||||
if (!qstrcmp(argv[i], "-no-gui"))
|
||||
return new QCoreApplication(argc, argv);
|
||||
return new QApplication(argc, argv);
|
||||
}
|
||||
|
||||
if (useGUI) {
|
||||
// start GUI version
|
||||
...
|
||||
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
|
||||
...
|
||||
// start non-GUI version...
|
||||
}
|
||||
return app.exec();
|
||||
|
||||
return app->exec();
|
||||
}
|
||||
//! [0]
|
||||
|
||||
|
@ -190,6 +190,15 @@ QApplicationPrivate::~QApplicationPrivate()
|
||||
any given time. For non-QWidget based Qt applications, use QGuiApplication instead,
|
||||
as it does not depend on the \l QtWidgets library.
|
||||
|
||||
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:
|
||||
|
||||
\snippet code/src_gui_kernel_qapplication.cpp 0
|
||||
|
||||
The QApplication object is accessible through the instance() function that
|
||||
returns a pointer equivalent to the global qApp pointer.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user