[Interest] Showing QGuiApplication/QML application on a given HWND ref.

Nuno Santos 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);

    return w;
}

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

Any ideas?

Thanks,
 
Nuno Santos
Founder / CEO / CTO
www.imaginando.pt
+351 91 621 69 62

> On 04 Jun 2015, at 13:50, Nuno Santos <nunosantos at imaginando.pt> wrote:
> 
> Hamish,
> 
> 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
> code:
> cocoaFromCarbonWin = [[NSWindow alloc] initWithWindowRef:window];
> 
> Do you think is my responsibility to create the NSWindow and then the NSView to provide to fromWinId?
> 
> Thanks,
> 
> Regards,
> 
> Nuno
> 
>> 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:
>>> Hi,
>>> 
>>> 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?
>> 
>> 
>> Hamish
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150604/e98e3e45/attachment.html>


More information about the Interest mailing list