Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-98564

Correctly initializing GDK when using Qt

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12, 5.15, 6.x
    • GUI: Look'n'Feel
    • None
    • Linux/X11

    Description

      Hello,
      consider the following code:

      #include <QApplication>
      #include <QLabel>
      #include <dlfcn.h>
      
      int main(int argc, char** argv)
      {
        using gdk_init_check_ptr = void *(*)(int*, char***);
        auto gdk = dlopen("libgdk-x11-2.0.so.0", RTLD_LAZY | RTLD_LOCAL);
        auto gdk_init_check = (gdk_init_check_ptr)dlsym(gdk, "gdk_init_check");
      
        gdk_init_check(nullptr, nullptr);
      
        QApplication app{argc, argv};
      
        QLabel label{"foo"};
        label.show();
      
        return app.exec();
      }
      

      It will work fine if the QT_QPA_PLATFORMTHEME is not gtk3.
      Otherwise, it either hangs (if gdk_init_check comes before QApplication) or crashes (if gdk_init_check comes after), likely because QGtk3 calls it too (through gtk_init).
      Sadly qgtk3 is the default platform theme on Ubuntu means that's where are a lot of users.

      What are my options to make sure that things work correctly no matter my user's platform themes ? My app loads external plug-ins from separate vendors and some require a GTK context to be initialized.

      Attachments

        1. QTBUG-98564.tar.gz
          0.8 kB
        2. answer.text
          0.7 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            jcelerier Jean-Michaƫl Celerier
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes