Can QWidget :: find widgets from another process?

The documentation for QWidget :: winId states (among other things): "If the widget is not native (alien) and winId is called, this widget will be provided with its own descriptor.

I'm not sure what β€œalien” means in this context, but now I prefer to ignore it. :)

So, assuming that my widget now has a corresponding native handle associated with it, can I pass this custom handle to another process and to QWidget :: find and return the actual QWidget to this second process?

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

If all this works:

  • How much control will be performed in the second process on this widget?

  • Will the first process receive user input events as if it were attached to the first user interface of the process and will the first process be able to update the widget as usual?

James

+4
source share
1 answer

Let's look at the sources of Qt.

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

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

So, if a widget with WId was created in another process, you cannot find it with QWidget::find . This function does not use the native OS functions to search widgets.

Also see the general description of other people's widgets in the Qt documentation:

Introduced in Qt 4.4, other people's widgets are widgets, an unknown window system. They do not have a built-in window handle with them. This feature greatly speeds up widget drawing, resizing and removing flicker.

+2
source

Source: https://habr.com/ru/post/1488284/


All Articles