tags:

views:

319

answers:

1

I am trying to create a HUD that is an NSPanel in Qt. I am using QMacCocoaViewContainer as suggested in the qt documentation.

In HUD.h

#import <QWidget>
#import <QMacCocoaViewContainer>


class HUD : public QMacCocoaViewContainer
{
public:
    HUD(QWidget* parent);
};

In HUD.mm

#import "HUD.h"
#import <Cocoa/Cocoa.h>

    HUD::HUD(QWidget* parent) : QMacCocoaViewContainer(0,parent)
    {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

        NSPanel *panel = [[NSPanel alloc] initWithContentRect: NSRectFromCGRect(CGRectMake(0,0,250,250))          
                 styleMask:NSHUDWindowMask | NSTitledWindowMask | NSUtilityWindowMask      
                 backing:NSBackingStoreBuffered 
                 defer:YES 
                 screen:[[NSApp mainWindow] screen]];

        setCocoaView(panel);


        [panel release];
        [pool release];
    }

Every time I run it however I get an error saying [NSPanel window]: unrecognized selector sent to instance 0x21231f0. Has anybody had any luck mixing Qt and Cocoa? Any tricks that you used to make it work?

+1  A: 

It sounds like this class is supposed to own a view, not a window. An NSPanel is a window, so giving it to something that wants a view is not going to work.

Either create a view and give that to the view container, or use an equivalent class that takes a window.

Peter Hosey