c++ubuntuqt5qapplicationqcoreapplication

Should my schizophrenic console/gui Qt5 program use QApplication or QCoreApplication?


My program will either open a GUI or not depending on some commandline parameters. Right now I am instantiating QApplication for my main event loop, but noticed that my program aborts when run from a headless machine (missing xorg/xcb) unless i specify some environment variables to trick it into believing there is an xorg running.

When I instead instantiate QCoreApplication I don't have access to activeWindow(). The code requiring activeWindow() will never run in the cases when the program is run headless (that is the purose of the commandline parameters).

So what I am asking is, would it be possible to make QApplication run without problems even on a headless machine, and simply not show any GUI?

What are my other options?


Solution

  • No, this is not possible. But you can create QCoreApplication or QApplication in dependent from command line args.