skip to Main Content

I recently upgraded my Ubuntu 20.04 WSL image from WSL1 to WSL2.

In WSL1, I was able to use QTCreator’s debugger (a wrapper around GDB) just fine. But after upgrading to WSL2, it now crashes once it reaches the constructor of QApplication().

Here is a basic example that crashes:

#include "mainwindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv); 
    MainWindow w;
    w.show();
    return a.exec();
}

Here is a stacktrace. I installed the libqt5core5a-dbgsym package, but this appears to make no difference in the stacktrace. If you know how to get debug symbols to work in this environment without re-compiling all of QT, please let me know!

Thread 1 (Thread 0x7ffff0b7bbc0 (LWP 31883)):
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
        set = {__val = {0 <repeats 12 times>, 228, 140737488338864, 140737488338864, 7758946189198844672}}
        pid = <optimized out>
        tid = <optimized out>
        ret = <optimized out>
#1  0x00007ffff5397859 in __GI_abort () at abort.c:79
        save_stage = 1
        act = {__sigaction_handler = {sa_handler = 0x7fffffffc058, sa_sigaction = 0x7fffffffc058}, sa_mask = {__val = {140737488339488, 140737488339496, 140737354022076, 140737488338896, 140737354046956, 3, 140737312309764, 0, 7758946189198844672, 140737488339032, 140737322294875, 3, 140737488339032, 140737488339520, 140737312310041, 0}}, sa_flags = 1318150912, sa_restorer = 0x7ffff61a1e5b}
        sigs = {__val = {32, 0 <repeats 15 times>}}
#2  0x00007ffff57ebaad in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
No symbol table info available.
#3  0x00007ffff5dcd7ae in QGuiApplicationPrivate::createPlatformIntegration() () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
No symbol table info available.
#4  0x00007ffff5dce708 in QGuiApplicationPrivate::createEventDispatcher() () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
No symbol table info available.
#5  0x00007ffff59f2f55 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
No symbol table info available.
#6  0x00007ffff5dd0543 in QGuiApplicationPrivate::init() () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
No symbol table info available.
#7  0x00007ffff640b3bd in QApplicationPrivate::init() () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
No symbol table info available.
#8  0x000055555555917f in main (argc=1, argv=0x7fffffffe718) at /mnt/c/source/myProject/main.cpp:105
        rc = 0
        a = <incomplete type>
        args = {_vptr.CLfxArgs = 0x0, m_threads = 0, m_autoFile = {static null = {<No data fields>}, d = 0x0}, m_firstFile = {static null = {<No data fields>}, d = 0x0}, m_fragDir = {static null = {<No data fields>}, d = 0x0}, m_forceFirst = false, m_materialsDir = {static null = {<No data fields>}, d = 0x0}, m_meshFile = {static null = {<No data fields>}, d = 0x0}, m_vmFile = {static null = {<No data fields>}, d = 0x0}, m_logFile = {static null = {<No data fields>}, d = 0x0}, m_lfxLog = false, m_testNum = 0, m_iterNum = 0, m_batch = false, m_noInit = false, m_qstarFile = {static null = {<No data fields>}, d = 0x0}, m_fragFuncNum = 42076, m_workingDir = {static null = {<No data fields>}, d = 0x7ffff5582510}}
        pTest = 0x0
        dAccumTime = 0
        batch = false
        szMsg = {static null = {<No data fields>}, d = 0x0}

Running a normal debug build works perfectly fine, everything behaves as expected. It only crashes in the debugger.

EDIT: If I attach GDB to the running process, I can move past the QApplication constructor just fine. If I try to start the application normally with GDB, I get an error similar to one that happens if the X-server cannot be found:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/x86_64-linux-gnu/libthread_db.so.1".
qt.qpa.xcb: could not connect to display localhost:0
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.


Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50

I properly exported a DISPLAY variable based on /etc/resolv.conf which works for the sake of launching QTCreator. So why GDB doesn’t like it, I don’t know.

EDIT: Further logs, if I enabled QT_DEBUG_PLUGINS:

(gdb) run
Starting program: /mnt/c/build/ubuntu20wsl/debug/myProject
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/x86_64-linux-gnu/libthread_db.so.1".
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "eglfs"
        ]
    },
    "archreq": 0,
    "className": "QEglFSIntegrationPlugin",
    "debug": false,
    "version": 330752
}


Got keys from plugin meta data ("eglfs")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqlinuxfb.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqlinuxfb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "linuxfb"
        ]
    },
    "archreq": 0,
    "className": "QLinuxFbIntegrationPlugin",
    "debug": false,
    "version": 330752
}


Got keys from plugin meta data ("linuxfb")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimal.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimal.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimal"
        ]
    },
    "archreq": 0,
    "className": "QMinimalIntegrationPlugin",
    "debug": false,
    "version": 330752
}


Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimalegl.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqminimalegl.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimalegl"
        ]
    },
    "archreq": 0,
    "className": "QMinimalEglIntegrationPlugin",
    "debug": false,
    "version": 330752
}


Got keys from plugin meta data ("minimalegl")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqoffscreen.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqoffscreen.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "offscreen"
        ]
    },
    "archreq": 0,
    "className": "QOffscreenIntegrationPlugin",
    "debug": false,
    "version": 330752
}


Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqvnc.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqvnc.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "vnc"
        ]
    },
    "archreq": 0,
    "className": "QVncIntegrationPlugin",
    "debug": false,
    "version": 330752
}


Got keys from plugin meta data ("vnc")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "archreq": 0,
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 330752
}


Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/mnt/c/build/ubuntu20wsl/debug/myProject/platforms" ...
loaded library "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so"
qt.qpa.xcb: could not connect to display localhost:0
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.

If I set the variable QT_QPA_PLATFORM=offscreen, then GDB does make it past the creation of the QApplication. However, the app’s window never appears.

LIBGL_ALWAYS_INDIRECT does not seem to help, and the XServer we use (X410) explicitly recommends against it, and it has caused problems for us in the past if set.

Some other posts on similar issues mention the package libxcb-cursor0, but I already have that. (version 0.1.1-4ubuntu1). I also have libxcb-xinerama0.

Just in case, I also checked the contents of /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms and they are libqeglfs.so libqlinuxfb.so libqminimal.so libqminimalegl.so libqoffscreen.so libqvnc.so libqxcb.so. So the X platform seems to be present, not missing.

  • QT version: 5.12.8
  • GCC version: 9.2 (Ubuntu 9.2-0ubuntu1~20.04.1)
  • Ubuntu: 20.04
  • QTCreator: 4.11.0
  • X410: 3.3.1

Current kit: enter image description here

2

Answers


  1. I have met this problem when I try to use qtcreator in the docker(also ubuntu 20.04). It shows the similar error info like yours. After doing research, I ran the command in my local PC and it works for me:

    xhost +local:
    

    However, it is not recommended because it opens up your X server to connections from any local user, effectively disabling access control. This command allows any local user to connect to your X server without restriction, which poses security risks. Please make sure this command is secure for your situation before running it.

    Login or Signup to reply.
  2. I already get Error:

    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even
    though it was found.

    and I could fix it by:

    sudo apt-get install libxcb-cursor0
    

    I underestand I need to install libxcb-cursor,For more detail please see :https://stackoverflow.com/a/76802978/9484913

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search