I am working on WSL2 (Ubuntu 20.04) and I have trouble setting up the $DISPLAY environment variable. More specificallly, I have a network configuration that allows me to ping devices connected to eth0, but I cannot run Qt apps.
(Edit: I run WSL2 on Windows 11)
When I run Qt software like Wireshark or in-house software from my company, I have this error message:
user@DESKTOP-XXX:~$ wireshark
qt.qpa.xcb : could not connect to display 0
qt.qpa.plugin: Couoldl not load the Qt platform plulgin "xcb" in "" even though it was found.
Looking this up, I understood that my $DISPLAY variable is not set properly. (I checked and the "xcb" plugin is installed and Qt locates it). I am now on a quest to understand the $DISPLAY envionment variable, and more specifically, how it works on WSL2. I found this great AskUbuntu answer about generalilties, but since WSL2 works a bit particularly (virtual machine, Hyper-V Virtual switch, etc), I can't understand what to set $DISPLAY to to communicate with something connected via Ethernet.
My network settings for WSL2:
I want to cmmunicate with a machine connected via Ethernet on my WSL2 computer. To do this, I set up the following configuration, that allows me to ping the machine:
- Hyper-V virtual manager Windows app: WSL virtual switch set up as "External network" via the Ethernet connector I use
- Network Connections Windows app:
- Ethernet:
- "Hyper-V extensible virtual switch" checked
- vEthernet (WLS):
- Hyper-V extenible virtual switch unchecked;
- IPV4: IP 10.0.0.10, gateway 10.0.0.3, favorite DNS 0.0.0.0
- Ethernet:
- Ubuntu network settings:
sudo ifconfig eth0 10.0.0.3 netmask 255.255.255.0
sudo ip route add default via 10.0.0.5 dev eth0
This setup allows me to ping my external machine via 10.0.0.2. (If I want to reach Internet via eth0, I need to add nameservers to resolv.conf.)
However, Qt apps still cannot reach it. And they cannot run at all. When I launch, for instance, Wireshark, I have the error message I stated above.
Some solutions I tried, inspired by things I found online:
user@DESKTOP-XXX:~$ export DISPLAY=0.0
qt.qpa.xcb : could not connect to display 0.0
user@DESKTOP-XXX:~$ export DISPLAY=8080
qt.qpa.xcb : could not connect to display 8080
user@DESKTOP-XXX:~$ export DISPLAY=10.0.0.2
qt.qpa.xcb : could not connect to display 10.0.0.2
user@DESKTOP-XXX:~$ export DISPLAY=10.0.0.2:0
infinite loading
DISPLAY
would be set for you), I'm expecting that's your problem. Also see What's the easiest way to run GUI apps on Windows Subsystem for Linux?. – NotTheDr01ds Sep 09 '22 at 12:18DISPLAY
, but... After a reboot, nothing. I'll go through those links. – rss.clement Sep 09 '22 at 12:29wsl --shutdown
, then restart Ubuntu withwsl ~ -e bash --norc --noprofie
. Is theDISPLAY
variable there at that point? – NotTheDr01ds Sep 09 '22 at 13:03C:\Users\me>wsl -e bash --norc --noprofile
bash-5.0$ echo $DISPLAY
:0
bash-5.0$ xeyes
--> window open with the eyes.
Great! Now I just have to see what is wrong in my usual Ubuntu bash.
– rss.clement Sep 09 '22 at 13:11~/.bashrc
. Start by looking for a line that is modifyingDISPLAY
. – NotTheDr01ds Sep 09 '22 at 13:12grep DISPLAY
returned nothing. I just have a few aliases (cmake, python, pip) in addition to default.bashsrc
. That being said, I know realize that this is likely not the problem, because if I runexport DISPLAY=:0
, I still have:Error: Can't open display: :0
withxeyes
and a similar message withwireshark
. – rss.clement Sep 09 '22 at 13:22wsl ~ -e bash --norc --noprofie
and this time,xeyes
returnsError: Can't open display: :0
. I'm perplexed, I will dig more on Monday. – rss.clement Sep 09 '22 at 15:05