QWidget::find 可以从不同的进程中找到小部件吗? [英] Can QWidget::find find widgets from a different process?

查看:36
本文介绍了QWidget::find 可以从不同的进程中找到小部件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QWidget::winId 的文档说明(其中包括其他事情)如果一个小部件是非本地(外来的)并且在其上调用了 winId,那么该小部件将被提供一个本地句柄."

The documentation for QWidget::winId states (among other things) "If a widget is non-native (alien) and winId is invoked on it, that widget will be provided a native handle."

我不确定在这种情况下外星人"是什么意思,但我现在选择忽略它.:)

I'm not sure what 'alien' means in that context, but I'm choosing to ignore it for now. :)

所以假设我的小部件现在有一个与之关联的有效本机句柄,然后我可以将该本机句柄传递给另一个进程并进入 QWidget::find 并在第二个进程中取回有效的 QWidget 对象?

So assuming that my widget now has a valid native handle associated with it, can I then pass that native handle to another process and into QWidget::find and get a valid QWidget object back within that second process?

除了显示/隐藏它并将其附加到父小部件之外,我可能不需要在第二个过程中对小部件做太多其他事情.(保证不会在第一个进程中附加到任何父小部件,并且在第一个进程的上下文中永远不可见).

I probably don't need to do too much else to the widget in the second process other than show/hide it and attach it to a parent widget. (It is guaranteed to not be attached to any parent widgets in the first process and never visible in the context of the first process).

如果以上都有效:

  1. 第二个进程对该小部件有多少控制权?

  1. How much control will the second process have over that widget?

第一个进程是否会像附加的一样接收用户输入事件到第一个进程的 UI,第一个进程是否能够正常更新小部件?

Will the first process receive user input events as if it were attached to the first process's UI, and will the first process be able to update the widget as normal?

詹姆斯

推荐答案

让我们来看看 Qt 源代码.

Let's take a look at Qt sources.

QWidget *QWidget::find(WId id)
{
    return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0;
}

find() 只有在 mapper 包含它时才能找到它.mapper 是一个静态的 QHash 变量.项目仅在 QWidgetPrivate::setWinId 方法中插入到此哈希中.

find() can find a widget only if mapper contains it. The mapper is a static QHash<WId, QWidget *> variable. Items are inserted in this hash only in the QWidgetPrivate::setWinId method.

因此,如果在另一个进程中创建了带有 WId 的小部件,则无法使用 QWidget::find 找到它.此函数不使用任何原生 OS 函数来查找小部件.

So, if a widget with a WId was created in another process, you can't find it using QWidget::find. This function doesn't use any native OS functions to find widgets.

另见 Qt 文档中关于外星小部件的一般描述:

Also see general description of alien widgets in Qt documentation:

在 Qt 4.4 中引入的外星小部件是未知的小部件窗口系统.它们没有关联的本机窗口句柄跟他们.此功能可显着加快小部件绘制速度,调整大小,并消除闪烁.

Introduced in Qt 4.4, alien widgets are widgets unknown to the windowing system. They do not have a native window handle associated with them. This feature significantly speeds up widget painting, resizing, and removes flicker.

这篇关于QWidget::find 可以从不同的进程中找到小部件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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