无法使QWindow :: fromWinId正常工作 [英] Cannot get QWindow::fromWinId to work properly

查看:470
本文介绍了无法使QWindow :: fromWinId正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Qt 5.9程序(在X11 Linux上)使用 QProcess 启动其他应用程序.我想控制这些应用程序生成的Windows,因此我获取了它们的 winId 值,并使用 QWindow :: fromWinId 来获取 QWindow 实例

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.

如果我使用 xwininfo 检查 winId 值,则会返回正确的信息,所以我知道它们很好.

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

我在做什么错了?

一个例子并没有多大帮助,但这里有:

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);

...基本上就是这样.appWindow是有效的QWindow实例,但与任何实际窗口均不相关.例如,如果我关闭(),它将返回true,但窗口不会关闭.

... 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.

即使我故意提供了错误的WId,最终结果也一样.

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

推荐答案

这不是解释为什么应该起作用的适当解决方案,但是它可能对某些人有帮助...

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

当我使用QWindow从Qt4 QX11EmebeddedContainer切换到Qt5实现时,我的应用程序遇到了同样的问题.我为解决/解决此问题所做的工作如下:

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:

客户端应用程序:

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

主应用程序:

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);

此后,我可以通过QWidget容器正确控制窗口.

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

这篇关于无法使QWindow :: fromWinId正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆