Qt apps work from Terminal-hosted WSL, but not from window WSL.
I am trying to run a Qt app, such as xeyes
, on WSL2 with Ubuntu 20.04, on Windows 11. When I launch it (xeyes, or Wireshark, or Qt-made software from my company), I have an error: Error: Can't open display: :0
.
Depending on the software, the error can be detailed as:
user@PC:~$ wiresharkqt.qpa.xcb: could not connect to display: :0qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found
For the sake of legibility, I will start code lines like that:
C:\Users\me> foo
is the Windows terminal (CMD)bash-5.0$ fight
is WSL called from the terminal (in the same window)user@PC:~$
is WSL started from Windows 11, from the desktop, in a separate window. It is supposed to be the exact same thing, but apparently not...
The weird thing is that I can run these if I start WSL2 from CMD. But not in my main WSL installation, the one that I start from a shortcut on my Windows desktop.
There are a lot of questions on the subject: Here, here, here. None of the solutions work for my system. My takeaway is that on start-up, WSL changes a network configuration.
How to reproduce
If I open Terminal (Windows command invite) and start WSL from there, it works:
C:\Users\me> wsl ~ -e bash --norc --noprofilebash-5.0$ xeyes # --> xeyes work
But if I open WSL directly from Windows, it does not work.
user@PC:~$ xeyesError: Can't open display: :0
And the weird thing is, once I opened WSL2, I can't start the app from CMD-hosted WSL again.
C:\Users\me> wsl ~ -e bash --norc --noprofilebash-5.0$ xeyesError: Can't open display: :0
My conclusion is that something in WSL2 changed network settings at launch.
Possible leads
I tried changing the DISPLAY
variable.
user@PC:~$ export DISPLAY=0.0.0.0
--> same erroruser@PC:~$ export DISPLAY=0.0.0.0:0
--> runs for several minutes, then same erroruser@PC:~$ export DISPLAY=10.0.0.3
(local IP) --> same erroruser@PC:~$ export DISPLAY=10.0.0.3:0
--> runs for several minutes, then same erroruser@PC:~$ export DISPLAY=[route]
putting the default route --> same error
In all cases, the problem must not be DISPLAY
, because it has the same default value in CMD and WSL2.
WSL from Windows desktop:
user@PC:~$ echo $DISPLAY
--> :0
WSL from Terminal:
C:\Users\me> wsl ~ -e bash --norc --noprofilebash-5.0$ echo $DISPLAYbash-5.0$ :0
I thought maybe WSL from desktop changes the network settings. But both ifconfig
and ip route show
return exactly the same parameters. I also have nothing in my .bashrc that could modify them, at least I think so.