Cannot get QWindow::fromWinId to work properly

被刻印的时光 ゝ 提交于 2021-02-19 06:20:28

问题


My Qt 5.9 program (on X11 Linux) launches other applications, using QProcess. I would like to have control over windows these applications spawn, so I obtain their winId value and use QWindow::fromWinId to get a QWindow instance.

The problem is these instances are invalid and do not represent the window they are supposed to.

If I check the winId values using xwininfo, the correct information is returned, so I know they are good.

What am I doing wrong?

Edit: An example won't help much, but here goes:

QProcess *process=new QProcess(this);
...
process.open()
... // wait until window appears
WId winId=PidToWid(process->processId()); // this function returns the    Window ID in decimal format. I test this with xwininfo, it's always correct
...
QWindow *appWindow=QWindow::fromWinId(winId);

... And that's basically it. appWindow is a valid QWindow instance, but it does not relate to the actual window in any way. For example, if I close() it, it returns true but the window does not close.

Even if I provide a wrong WId on purpose, the end result is the same.


回答1:


This is not proper solution with explanation why it should work, however it may be helpful for somebody...

I had the same issue with my application when I switched from Qt4 QX11EmebeddedContainer to Qt5 implementation using QWindow. What I did to resolve / fix this issue was following:

Client application:

widget->show(); //Widget had to be shown
widget->createWinId();
sendWinId(widget->winId()); //Post window handle to master app where is constructed container

Master application:

QWindow* window = QWindow::fromWinId(clientWinId);
window->show(); //This show/hide toggle did trick in combination with show in client app
window->hide();
QWidget* container = QWidget::createWindowContainer(window, parentWindowWidget);

After this I was able to control window properly through QWidget container.



来源:https://stackoverflow.com/questions/45061803/cannot-get-qwindowfromwinid-to-work-properly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!