Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved Qt Wayland client wait for Wayland Compositor

    Mobile and Embedded
    wayland
    3
    5
    465
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Mmader87 last edited by aha_1980

      I am creating my own wayland compositor and client program.

      In an ideal world, the compositor will be loaded before the client application. I have encountered a situation where this is not true.

      However, I was wondering if there was a way for the client app to wait programmatically for the compositor before running.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        Can you describe the situation when it happens ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • M
          Mmader87 last edited by

          Yes, I get the following message when I try to run my wayland client.

          Failed to create wl_display (No such file or directory)
          qt.qpa.plugin: Could not load the Qt platform plugin "wayland" 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: wayland-egl, wayland.

          I know this is a pretty standard message. In my situation I know it is because the wayland compositor hasn't fully initialized yet. If I manually wait a second or two to launch the wayland client everything works fine. However, adding in wasted time is undesired as boot time is critical.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            How are you starting the compositor ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • ehopperdietzel
              ehopperdietzel last edited by

              You could use the wayland-client library like this before your instantiate your QApplication:

              #include <QApplication>
              #include <wayland-client.h>
              #include <unistd.h>
              
              int main(int argc, char *argv[])
              {
                  struct wl_display *display = NULL;
              
                  while(!display)
                  {
                      // Return NULL if no compositor avaliable in wayland-0
                      display = wl_display_connect(NULL);
                      
                      // Wait 200 ms so you dont overuse your CPU
                      usleep(200000);
                  }
                  
                  // Disconnect because QApplication will stablish its own connection
                  wl_display_disconnect(display);
              
                  // Start the app
                  QApplication app(argc,argv);
                  
                  ...
                  
              }
              

              Its a bit ugly but it should work.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post