Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
None
-
6.4.1
-
None
-
System: Manjaro Linux (Xfce, X11)
Qt version: 6.4.1
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.