Skip to content

Commit

Permalink
[Server][Bugfix] Test if the environ variable DISPLAY is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Oct 23, 2017
1 parent 13a00aa commit 7bfd60a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/server/qgis_map_serv.cpp
Expand Up @@ -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"

Expand All @@ -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();
Expand Down

0 comments on commit 7bfd60a

Please sign in to comment.