PDA

View Full Version : Launching an application without display



tarod
2nd July 2012, 09:31
Hello Qt Devs,

I'm developing in Linux and trying to launch an application in a Linux server. The server doesn't have connected a monitor, so the environment variable "DISPLAY" is not defined.

The application is requesting a DISPLAY, so I'm forced to define the variable although there isn't any display.

Define DISPLAY is a solution, but I prefer to avoid that option.

Thanks.

wysota
2nd July 2012, 09:59
Don't link against QtGui (Add QT -= gui to your project file).

tarod
2nd July 2012, 10:49
Thank you. I'm gonna try it.

tarod
3rd July 2012, 07:57
A little story.

Link or not against QtGui (adding QT -= gui to your project file) didn't work for me. The application requires the display anyway.

The problem is that I use QApplication in my code, so the application needs a display or X server.

I was testing QCoreApplication instead QApplication , but it is not suitable in my case because I'm using QPainter with drawText functions. Searching on the Internet we can found there is a bug when QCoreApplication and QPainter are used together.

http://comments.gmane.org/gmane.comp.lib.qt.general/17392

I don't know if the bug is solved nowadays. My Qt version is 4.2.3 (yep, old, but it's not my fault!)

So, after reading the QApplication source code more thoroughly, changing this line:

QApplication app(argc, argv);

to this:

QApplication app(argc, argv, false);

The QApplication no longer complains about not finding an X server, and QPainter works well.

Please, tell me you opinions about this issue.

wysota
3rd July 2012, 08:16
If your application requires X11, then you need X11. You can upgrade to newer Qt that doesn't require X to use fonts.

tarod
3rd July 2012, 08:38
Well, X11 is already installed.

Anyway, do you think QCoreApplication is also necessary in addition to "QT -= gui"?

high_flyer
3rd July 2012, 11:14
Anyway, do you think QCoreApplication is also necessary in addition to "QT -= gui"?
if you don't need GUI facilities, then yes, use QCoreApplication instead of QApplication, and as wysota suggested, "QT -= gui"