[SOLVED] How to access to UIApplication from a Qt project
-
Dear all,
I'm using the Qt 5 stable from the git repository (30 may version), and I need to call a method of the UIApplication ... but I don't know to do that for various reasons:- Qt projects are C++ based ... UIApplication is an object-C class. How can I call an object-C object method from a C++ method ??
- How can I add an object-C source file to a Qt project ??
Can you give me some little example that explain how to call iOS native methods from Qt project ??
Thanks,
Gianluca. -
I did my homework ... and I solved the problem.
I post here a sketch of the solution:create at least two files: myNativeWrapperFunctions.h e myNativeWrapperFunctions.mm; The .h file declare C functions that can be called from C++ and in the .mm file they will implemented using objective-C and accessing to the native iOS frameworks
simply add the .h to the HEADERS and .mm to SOURCES into the QMake project
using QMake create the XCode project; XCode knows how to compile .mm files (that's indicate objective-C that can be mixed with C++)
include the header myNativeWrapperFunctions.h into a C++ source code and call the functions
That's it.
Gianluca. -
Hello,
Can you post exactly what code you used in your objective C files to get access to the UIApplication? Would it be possible to write your own AppDelegate (to handle things like background fetch) and you could set that AppDelegate similar to UIApplicationMain(...)?
-
Actually I was able to get this in a similar fashion. I made a header file that had my C function declaration in it. I imported that to my .mm file. I was then able to call that C function from my C++ source. The implementation of the C function in the .mm can call native ios Objective C
-
Were you able to write your own UIApplicationdelegate without any problems?
[quote author="dcole" date="1395861152"]Hello,Can you post exactly what code you used in your objective C files to get access to the UIApplication? Would it be possible to write your own AppDelegate (to handle things like background fetch) and you could set that AppDelegate similar to UIApplicationMain(...)?[/quote]