Skip to content

Commit a6964b5

Browse files
authoredOct 23, 2017
Merge pull request #5413 from rldhont/server-bugfix-display
[Server][Bugfix] Test if the environ variable DISPLAY is defined
2 parents 1d043f3 + 7bfd60a commit a6964b5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed
 

‎src/server/qgis_map_serv.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
//for CMAKE_INSTALL_PREFIX
2020
#include "qgsconfig.h"
2121
#include "qgsserver.h"
22+
#include "qgslogger.h"
23+
#include "qgsserverlogger.h"
2224
#include "qgsfcgiserverresponse.h"
2325
#include "qgsfcgiserverrequest.h"
2426

@@ -39,7 +41,25 @@ int fcgi_accept()
3941

4042
int main( int argc, char *argv[] )
4143
{
42-
QgsApplication app( argc, argv, getenv( "DISPLAY" ), QString(), QStringLiteral( "server" ) );
44+
// Test if the environ variable DISPLAY is defined
45+
// if it's not, the server is running in offscreen mode
46+
// Qt supports using various QPA (Qt Platform Abstraction) back ends
47+
// for rendering. You can specify the back end to use with the environment
48+
// variable QT_QPA_PLATFORM when invoking a Qt-based application.
49+
// Available platform plugins are: directfbegl, directfb, eglfs, linuxfb,
50+
// minimal, minimalegl, offscreen, wayland-egl, wayland, xcb.
51+
// https://www.ics.com/blog/qt-tips-and-tricks-part-1
52+
// http://doc.qt.io/qt-5/qpa.html
53+
const char *display = getenv( "DISPLAY" );
54+
bool withDisplay = true;
55+
if ( !display )
56+
{
57+
withDisplay = false;
58+
qputenv( "QT_QPA_PLATFORM", "offscreen" );
59+
QgsMessageLog::logMessage( "DISPLAY not set, running in offscreen mode, all printing capabilities will not be available.", "Server", QgsMessageLog::INFO );
60+
}
61+
// since version 3.0 QgsServer now needs a qApp so initialize QgsApplication
62+
QgsApplication app( argc, argv, withDisplay, QString(), QStringLiteral( "server" ) );
4363
QgsServer server;
4464
#ifdef HAVE_SERVER_PYTHON_PLUGINS
4565
server.initPython();

0 commit comments

Comments
 (0)