Checking if running as command-line (QCoreApplication) or GUI
-
Is it correct to write:
if (qApp) { // Do gui stuff } else { // Do command line stuff }Thanks, David
@Perdrix
I imagine that is a reasonable test if you want to do a Qt call, as in: "is there aQApplicationobject?"A global pointer referring to the unique application object. It is equivalent to QCoreApplication::instance(), but cast as a QApplication pointer, so only valid when the unique application object is a QApplication.
However, are you intending to use single-source with two separate compilations/links, one for GUI and one for console? Because if you are thinking you can do just one compilation/link and decide at runtime whether to run as GUI or command line you are going to stall. Under Windows at least --- which ISTR you use --- an executable is linked as either "windows" (GUI) or "console" (command-line) and you are stuck with that at runtime.