Graphical Toolkits for OS X: wxPython
Subject:   Request: Mixing Qt and Cocoa?
Date:   2007-06-18 10:30:50
From:   ghiebert
Response to: Request: Mixing Qt and Cocoa?

I've been playing around with Qt for the past week, after some interest was shown at work of moving our MFC- and Delphi-based code over to Qt.

One part of our code is a set of about 150 different "settings" dialogs, which can be accessed in any applications as modal dialogs through a simple function call. Up to this point, this functionality is available only to Windows users, even though we provide our product on five other platforms.

I had no real difficulty in bringing a Qt dialog up inside a Cocoa application and having it active at the same time as the main Cocoa app. There were just a few issues to take care of:

1) I had to call "qt_mac_set_native_menubar(false)" at the right point to prevent Qt from taking over my application's menu bar.
2) The Qt event loop has to occur in the same thread as the main Cocoa event loop, from what I can tell. For this, I just scheduled an NSTimer to call QApplication::processEvents() periodically from the Cocoa application's run loop, in place of calling myQtApp.exec(). (I guess there'd be no need to even do this if I restrict my calls to use modal Qt dialogs.)

There are still issues with my work: I haven't done any intensive testing of the setup, and I need to find a way to get proper Carbon window references for the Qt windows if I want to get fancy, for example. However, initial results are very encouraging towards bringing Qt components into my Cocoa app in some form.