Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 2148  / 2 Years ago, wed, july 6, 2022, 7:44:14

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





  • 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

More From » 20.04

 Answers
7

Throwing this out as another answer (workaround) if you want to go this route. It doesn't "fix" the problem, but you should be able to fall back to the "Windows 10" way of getting X running, which is to either:



  • Install a third-party X server such as VcXsrv (or one of many others)

  • Run via XRDP


That would take WSLg out of the picture, and allow you to run as long as you have a proper network connection between the Windows host and WSL2.


Some details in:



WSLg is nice, but if you need that custom networking configuration, and you can't get WSLg working with it, it's nice to have the "fallbacks" at least.


[#246] Friday, July 8, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ranquctive

Total Points: 391
Total Questions: 103
Total Answers: 104

Location: South Sudan
Member since Thu, Feb 4, 2021
3 Years ago
ranquctive questions
Sun, Apr 10, 22, 23:19, 2 Years ago
Sun, Nov 21, 21, 22:40, 3 Years ago
Sun, Apr 3, 22, 17:43, 2 Years ago
Thu, Mar 3, 22, 03:08, 2 Years ago
;