Calling Qt-Gui from native iOS Gui & Vice versa

  • I currently have a native iOS GUI and a Qt-GUI. I'm trying to switch from one to another.

    To be clear: When i click on a button on the native GUI i want the Qt-GUI to show up and vice versa.

    I already found out which libraries i have to add to be able to use the Qt-Stuff. I created a QApplication in the file:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {
        // receive int argc, and char** argv for the QApplication.
        _qApp = new QApplication(_argc, _argv);

    Furthermore my Qt application looks (at the moment) like this:

    void createQtGUI() {
        QPushButton* btn = new QPushButton("Some Button");
        QLabel* lbl = new QLabel("QTGui");
        QVBoxLayout* layout = new QVBoxLayout();
        QWidget* window = new QWidget();

    I'm calling the createQtGUI method in my when pressing a button in the native iOS GUI. The code runs without throwing any error, but:

    The Qt-GUI is not shown. The application still shows the native gui without switching to the Qt-GUI.

    Has anybody got any idea how to fix that?

  • I've finally found out what was missing:

    The Qt-Objects provide a method called winId(). This method returns a WId which actually is (on iOS) an UIView*.

    You have to add that UIView* as Subview to your main view.

    In order to achieve that I changed my createQtGUI method as follows:

    WId createQtGUI() {
        ... // nothing changed here (only at the end)
        return window->winId();

    And In my (where I call my method):

    - (IBAction)ButtonClicked:(id)sender {
        UIView* newView = (__bridge UIView*)reinterpret_cast<void*>(createQtGUI());
        [self.view addSubview:newView];

    Note: The double cast (__bridge UIView*)reinterpret_cast<void*>(...) is necessary because you can't just cast from WId to UIView* in Objective-C++.

  • Hi all.
    I'd rather raise this old topic, than create an identical one.
    I'm trying to achieve exactly the same functionality using iOS12 (since yesterday) and Qt 5.10.1 (more recent versions are to be tested yet). It does not work. No updates, no events are coming to my Qt window, and it's not being drawn. Does anyone has a working solution?

    I have gone through following resources without success:

    p.s. I will post sample code a bit later.

    Thanks in advance!


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.