1

Using QPainter in a non-GUI environment may be useful f.e. to generate PDF's on (web)servers.

However QPainter depends on QGuiApplication, which results in a runtime error:

qt.qpa.screen: QXcbConnection: Could not connect to display Could not connect to any X display.

How could I use QPainter in a non-GUI environment (no output screen is available)?

m7913d
  • 10,244
  • 7
  • 28
  • 56

1 Answers1

2

You should start your application with the following command line argument: -platform minimal:

minimal is provided as an examples for developers who want to write their own platform plugins. However, you can use the plugin to run GUI applications in environments without a GUI, such as servers.

Note that -platform offscreen seems to be required to support fonts, i.e. painting text, otherwise black squares are shown instead of the actual text.

Further reading & references

m7913d
  • 10,244
  • 7
  • 28
  • 56