Can QWidget::find find widgets from a different process?

孤街浪徒 提交于 2019-12-04 03:57:11

问题


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

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

If all the above works:

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

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

James


回答1:


Let's take a look at Qt sources.

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

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.

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.

Also see general description of alien widgets in Qt documentation:

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.



来源:https://stackoverflow.com/questions/17319853/can-qwidgetfind-find-widgets-from-a-different-process

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