Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Crash in QGuiApplication::font but..



  • I've upgraded a server I'm running to Ubuntu Server 20.04. Another goal of the upgrade was moving my software from Qt 4.x to 5.x

    The server is basically headless (definitely no desktop environment)

    The server receives images from other sources. One program loads the images into a QImage and paints on them using a QPainter adding a label to the modified images.

    Previously when I was using Qt 4.x and I was able to use QApplication with the "No GUI" flag, and everything "Just worked"

    The same program compiles just fine with Qt 5.x, after changing to QCoreApplication, but that results in a segfault when trying to use fonts (in QGuiApplication::font)

    If I use QGuiApplication, I get the following:

    "qt.qpa.xcb: could not connect to display
    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

    Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb."

    Do I need to stick with Qt 4.x for this one program? Any other work arounds? Can I install one of those plugins without a desktop environment?

    Regards,

    John


  • Moderators

    @jmorris_nv said in Crash in QGuiApplication::font but..:

    "qt.qpa.xcb: could not connect to display
    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

    Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb."

    Do I need to stick with Qt 4.x for this one program? Any other work arounds? Can I install one of those plugins without a desktop environment?

    You can tell your app to use the offscreen plugin instead of the xcb plugin by passing the -platform flag from the console:

    ./myapp -platform offscreen

    Previously when I was using Qt 4.x and I was able to use QApplication with the "No GUI" flag, and everything "Just worked"
    The same program compiles just fine with Qt 5.x, after changing to QCoreApplication, but that results in a segfault when trying to use fonts (in QGuiApplication::font)

    It segfaults because QCoreApplication::font() does not exist. You must use QGuiApplication or QApplication.

    Make sure your qApp pointer isn't getting cast to the wrong class. I believe that if you remove all instances of #include <QApplication> or #include <QGuiApplication> from your code, it will stop compiling.



  • After some quick testing, looks like "--platform offscreen" did the trick.

    Many thanks!


Log in to reply