Mix QT with objective-c to develope an ios application

  • hi, i want to implement an ios application with qt. I've installed qt on mac and i want to use objective-c code in qt c++. to fetch iphone address book, then i want to use it in qt c++. how can i do that? how can i embed objective-c code in qt c++? are there a way like androidextra for ios?

  • I found a solution : http://qt-project.org/forums/viewthread/40299

    "Create a C++ header that contains the function you’ll use to invoke the native file selection dialog.

    Then write a mm file that implements the function calling the Objective-C classes/code you need.

    Add the mm file to the OBJECTIVE_SOURCES variable."

  • Lifetime Qt Champion


    You can also take a look at Qt's code to see example on how to do that cleanly

  • Hi,
    For use objective-c class in qt c++, I've used the code from this link: http://stackoverflow.com/questions/1061005/calling-objective-c-method-from-c-method

    int MyObjectDoSomethingWith(void *myObjectInstance, void *parameter);
    void someMethod(void *myObjectInstance, void *parameter);

    #import <Foundation/Foundation.h>

    @interface MyObject : NSObject

    // The Objective-C member function you want to call from C++

    • (int) doSomethingWith:(void *) aParameter;


    void MainWindow::someMethod(void *objectiveCObject , void *aParameter)
    int ret = MyObjectDoSomethingWith(objectiveCObject ,aParameter )

    #import "MyObject.h"

    @implementation MyObject

    // C "trampoline" function to invoke Objective-C method
    int MyObjectDoSomethingWith (void *self, void *aParameter)
    // Call the Objective-C method using Objective-C syntax
    return [(id) self doSomethingWith:aParameter];

    • (int) doSomethingWith:(void *) aParameter
      // The Objective-C function you wanted to call from C++.
      // do work here..
      return 21 ; // half of 42

    OBJECTIVE_SOURCES += MyObject.mm
    LIBS += -framework Foundation

    Afetr building, i got these errors:
    symbol(s) not found for architecture x86_64
    linker command failed with exit code 1 (use -v to see invocation)

    I use qt5.3 on mac, please help me.

  • I found a solution. Please go to : http://qt-project.org/forums/viewthread/48250/

Log in to reply

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