Important: Please read the Qt Code of Conduct -

Embed Qt in an X11 window

  • Hi,

    I am trying to embed Qt in an X11 window. My current approach uses the QWidget::create function:
    class QTkMainWindow: public QWidget {
    QTkMainWindow(WId win)
    :QWidget() {
    QWidget::create(win, true, true);

    void createApp(int argc, char **argv) {
        Display *d;
        Window w;
        XEvent e;
        int s;
        d = XOpenDisplay(NULL);
        s = DefaultScreen(d);
        w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1,
                           BlackPixel(d, s), WhitePixel(d, s));
        XSelectInput(d, w, ExposureMask | KeyPressMask);
        QApplication *qapp = new QApplication(argc, argv);
        QTkMainWindow *win = new QTkMainWindow(w);
        XMapWindow(d, w);
        while (1) {
            XNextEvent(d, &e);
            if (e.type == KeyPress)


    but unfortunately I get two windows instead of one.

    Can anyone give me some suggestion about what I might be missing or what different approach should I use?


  • Moderators

    Can I ask why? Qt on Linux uses X11 so it will create a X11 window for you automatically, no need to do it by hand... but you probably do have some specific use case.

  • I am currently trying to make a new Qt display manager for a program that actually uses Tk and the whole logic is for Tk, so embedding Qt will help me reduce a lot of effort.
    I was unsuccessful embedding Qt in Tk using the same approach, so I tried to embed in a raw X11 window to see if I miss something and also because I found more reference to Qt in X11 then Qt in Tk.

    So any suggestion on how to embed Qt in either X11 or Tk because it would really help me?

Log in to reply