[Interest] [OS X] creating a QDialog from a WId?
René J. V. Bertin
rjvbertin at gmail.com
Wed Dec 9 00:42:24 CET 2015
Thiago Macieira wrote:
> This is a crash inside the Cocoa plugin. Unfortunately, I can't read Objective
It is indeed...
> C++ code, so I have absolutely no clue what this line does or how it can even
> crash:
>
> [m_contentView removeFromSuperview];
Supposing that is indeed the crashing function (my qcocoawindow.mm:1154 says
[contentView retain]), then this is what it does:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/#//apple_ref/occ/instm/NSView/removeFromSuperview
but there are a few more or less self-evident ways this can go wrong:
- the (m_)contentView is not initialised, which means the removeFromSuperView
message is sent to someplace it shouldn't go
- the instance was released already
- the method is called during display
and then there is the possibility that m_contentView or contentView correspond
to a window that belongs to another application, because apparently a WId can be
a simple cast of an NSView* :
WId QCocoaWindow::winId() const
{
return WId(m_contentView);
}
It's not impossible that AppKit itself doesn't have any way of knowing whether
an NSView is owned by the calling application or not because it's not designed
to allow application to mess with each others' windows (other than through
formal channels). In that case you'd have to keep track of all owned objects
that can be exported as WIds, and do a lookup in each public function that
accepts a WId. Sounds like a considerable overhead...
BTW, in principle it is possible with ObjC to send messages to (call methods of)
objects that belong to another application. That does require some extra code
however, and I cannot remember if each and every method can be used that way.
I've never actually used this myself, but I have some doubts that you could just
pass pointers to instances around and send them messages.
R.
More information about the Interest
mailing list