[Interest] Showing QGuiApplication/QML application on a given HWND ref.
nunosantos at imaginando.pt
Thu Jun 4 19:33:27 CEST 2015
I have tried to make a function that turns a WindowRef into a QWindow with the following code in Cocoa:
QWindow* IVstEditor::fromWindowRef(void *ptr)
NSWindow *nsw = [[NSWindow alloc] initWithWindowRef:ptr];
NSView *nsv = (NSView*)nsw.contentView;
NSLog(@"frame - %f %f %f %f", nsv.frame.origin.x, nsv.frame.origin.y, nsv.frame.size.width, nsv.frame.size.height);
nsv.layer.backgroundColor = [[NSColor yellowColor] CGColor];
QWindow *w = QWindow::fromWinId((WId)nsw);
If I don’t use the QWindow as a parent of QQuickView, it doesn’t crash but I can’t manage to have the contentView layer painted yellow (just to ensure that i’m able to control the window), and the frame size comes at zero when the window being displayed is 1024x768. The console also outputs the following:
2015-06-04 18:28:18.413 Live[33079:217104] A Carbon window's attributes couldn't be gotten.
2015-06-04 18:28:18.413 Live[33079:217104] A Carbon window's features couldn't be gotten.
2015-06-04 18:28:18.413 Live[33079:217104] Couldn't get window modality: error=-5600
2015-06-04 18:28:18.413 Live[33079:217104] frame - 0.000000 0.000000 0.000000 0.000000
Founder / CEO / CTO
+351 91 621 69 62
> On 04 Jun 2015, at 13:50, Nuno Santos <nunosantos at imaginando.pt> wrote:
> Your tip was right.
> QWindow::fromWinId is expecting a NSView:
> plugins/platforms/cocoa/qcocoawindow.mm: NSView *foreignView = (NSView *)WId(tlw->property("_q_foreignWinId").value<WId>());
> But what I’m giving is a Carbon WindowRef.
> I have found code to make an NSWindow from WindowRef:
> You can create an NSWindow object for a Carbon window by allocating an NSWindow object and
> then initializing the object using the initWithWindowRef: method, as shown in the following line of
> cocoaFromCarbonWin = [[NSWindow alloc] initWithWindowRef:window];
> Do you think is my responsibility to create the NSWindow and then the NSView to provide to fromWinId?
>> On 04/06/2015, at 09:34, Hamish Moffatt <hamish at risingsoftware.com <mailto:hamish at risingsoftware.com>> wrote:
>> On 04/06/15 17:44, Nuno Santos wrote:
>>> Unfortunately this technic doesn’t seem to be working on Mac. Not sure if this is a BUG.
>>> It is able to create the QQuickView, but as soon as it instantiates QQuickView, it crashes:
>>> if (!window)
>>> window = QWindow::fromWinId((WId)ptr); // line that causes the crash
>>> 2015-06-04 08:38:37.892 Live[88624:8396551] -[NSHIObject setPostsFrameChangedNotifications:]: unrecognized selector sent to instance 0x1b333860
>>> Does this say something to anyone?
>> "unrecognized selector" means a method was called that doesn't exist. Or more likely, the object you passed to fromWinId was not the type that the Cocoa platform plugin expected.
>> The platform plugin is expecting an NSView*, and maybe what you have is an NSWindow*. (I don't know much about Cocoa.) Or maybe it's not a Cocoa window at all?
> Interest mailing list
> Interest at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Interest