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

Crash when calling winID() on window handle

    XMLWordPrintable

Details

    • Linux/X11

    Description

      Hi everyone,

      In my project I need to get Qt window ID for further usage, so I have a try in the following simple example:

      #include "mainwindow.h"
      #include "./ui_mainwindow.h"
      
      #include <QPushButton>
      #include <QWindow>
      #include <QMessageBox>
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          QObject::connect(ui->btnGetParent, SIGNAL(clicked()), this, SLOT(btnGetParent_click()));
      }
      
      void MainWindow::btnGetParent_click()
      {
          WId parentId;
      
          parentId = this->windowHandle()->parent()->winId();
      
          char buffer[100];
          sprintf(buffer, "Parent window: %d", (long) parentId);
      
          QMessageBox::information(this, "Info", QString(buffer));
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      

      However, when executing, it crashes here:

      parentId = this->windowHandle()->parent()->winId();
      

      Seems so strange, as at this time the main window should be activated and rendered, and the native window handle shall be accessed.

      I've attached the GDB backtrace and source code to this bug report. Looking forward to precious advice.

      Attachments

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            anclark AnClark Liu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: