[Qt-interest] is it possible to get a non-changing winId?

Denis Dzyubenko denis.dzyubenko at trolltech.com
Mon Jun 8 12:54:45 CEST 2009


Hi Ross,

Ross Bencina wrote:
>> However winId() shouldn't change unless you reparent a widget, or
>> hide/show it several times.
> 
> OK, well I create it with parent == 0 and then reparent it later. This 
> is kind-of necessary because creating the parent is expensive and I 
> don't want to do it if the child fails.
> 
>> However winId() shouldn't change unless you reparent a widget, or
>> hide/show it several times.
> 
> This sounds vague enough to be dangerous for my use-case. I guess 
> reparenting it is what's causing the problems.
> 
>> In worst case you can try create a native window id manually and attach
>> it to QWidget with a QWidget::create() function.
> 
> Does this _guarantee_ that Qt won't change the HWND? If so, sounds like 
> my best option..

No, I am afraid that Qt will still try to recreate a native winid when 
reparenting a widget. I guess Qt only guarantees that window id will not 
be changed while the widget is visible.
The solution for you might be either creating a widget with a parent and 
_then_ using winId(), or creating a native window handle by yourself, 
and afterwards, when you are ready to show it, use the QWidget::create 
function to attach window handle to qwidget, which was already 
reparented to the right parent widget.

-- 
Denis Dzyubenko
Software Engineer
Nokia, Qt Software



More information about the Qt-interest-old mailing list