[Server][Bugfix] Test if the environ variable DISPLAY is defined

This commit is contained in:
rldhont 2017-10-20 09:30:43 +02:00
parent 13a00aae30
commit 7bfd60ab78

View File

@ -19,6 +19,8 @@
//for CMAKE_INSTALL_PREFIX
#include "qgsconfig.h"
#include "qgsserver.h"
#include "qgslogger.h"
#include "qgsserverlogger.h"
#include "qgsfcgiserverresponse.h"
#include "qgsfcgiserverrequest.h"
@ -39,7 +41,25 @@ int fcgi_accept()
int main( int argc, char *argv[] )
{
QgsApplication app( argc, argv, getenv( "DISPLAY" ), QString(), QStringLiteral( "server" ) );
// Test if the environ variable DISPLAY is defined
// if it's not, the server is running in offscreen mode
// Qt supports using various QPA (Qt Platform Abstraction) back ends
// for rendering. You can specify the back end to use with the environment
// variable QT_QPA_PLATFORM when invoking a Qt-based application.
// Available platform plugins are: directfbegl, directfb, eglfs, linuxfb,
// minimal, minimalegl, offscreen, wayland-egl, wayland, xcb.
// https://www.ics.com/blog/qt-tips-and-tricks-part-1
// http://doc.qt.io/qt-5/qpa.html
const char *display = getenv( "DISPLAY" );
bool withDisplay = true;
if ( !display )
{
withDisplay = false;
qputenv( "QT_QPA_PLATFORM", "offscreen" );
QgsMessageLog::logMessage( "DISPLAY not set, running in offscreen mode, all printing capabilities will not be available.", "Server", QgsMessageLog::INFO );
}
// since version 3.0 QgsServer now needs a qApp so initialize QgsApplication
QgsApplication app( argc, argv, withDisplay, QString(), QStringLiteral( "server" ) );
QgsServer server;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
server.initPython();