Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt 5.1 QApplication Without Display - QXcbConnection: Could not connect to display
Forum Updated to NodeBB v4.3 + New Features

Qt 5.1 QApplication Without Display - QXcbConnection: Could not connect to display

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 7.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    veenix
    wrote on last edited by
    #1

    I'm using Qt5.1 and I'm trying to create a QApplication without a display. I need to draw text with QPainter, so I need to use QApplication (or QGuiApplication), otherwise I get a segfault.

    The application worked fine in Qt4.8, but fails in Qt5.1 on a headless version of Ubuntu with the error:

    @"QXcbConnection: Could not connect to display".@

    In Qt 4.8, I was able to use the following constructor with GUIenabled = false to create a QApplication that did not require a display:

    @QApplication::QApplication ( int & argc, char ** argv, bool GUIenabled )@

    In Qt5.1, the constructor for QApplication no longer has the GUIenabled flag.

    I scanned the source code briefly, and there does seem to be a flag in the QApplication constructor, but it is undocumented as to what options can be used in that flag. Using "false" does not work.

    How can I create a QApplication without a display? Is there an alternative method to telling QApplication GUIenabled = false? Alternatively, can I create a QCoreApplication that will not segfault when drawing text with QPainter on a QImage?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      QPainter requires QGuiApplication, and QGuiApplication ultimately links you to X11 through libQt5Gui.so.5

      One way I can see you getting this to fly is to fake an X server using "Xvfb":http://www.wikipedia.org/wiki/Xvfb Clearly this will not work if there is no X at all on the target machine.

      There is an "offscreen" platform driver that might work. Start your app with "-platform offscreen". Edit: Scratch this, it requires X11 libraries also.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        veenix
        wrote on last edited by
        #3

        I tried "-platform offscreen", but I got the error:

        QFontDatabase: Cannot find font directory '/***/lib/fonts' - is Qt installed correctly?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lucasrangit
          wrote on last edited by
          #4

          I had the same problem trying to run my QTestLib QGuiApplication unit tests on a headless build system. I worked around it by providing a X virtual server.

          Xvfb :1 &
          DISPLAY=:1 make check
          pkill Xvfb
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved