Skip to content

Instantly share code, notes, and snippets.

@alediaferia
Created December 31, 2017 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alediaferia/5fbb50e18ec9ee6310bea0620d8be82a to your computer and use it in GitHub Desktop.
Save alediaferia/5fbb50e18ec9ee6310bea0620d8be82a to your computer and use it in GitHub Desktop.
Qt within Objective-C
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSProcessInfo *procInfo = [NSProcessInfo processInfo];
NSArray *arguments = [procInfo arguments];
int argc = arguments.count;
// we need a strong reference for the
// argv because it is required to stay
// valid as long as the QGuiApplication instance
// is valid
_argv = (char**)malloc(sizeof(char*) * argc);
for (int i = 0; i < argc; ++i) {
NSString *arg = [arguments objectAtIndex:i];
_argv[i] = (char *)(malloc([arg lengthOfBytesUsingEncoding:[NSString defaultCStringEncoding]]));
strcpy(_argv[i], [arg cStringUsingEncoding:[NSString defaultCStringEncoding]]);
}
// make sure you keep a strong reference
// to the QGuiApplication instance.
// you can later free it inside the
// - (void)applicationWillTerminate:(UIApplication *)application
// delegate method
_qApp = new QGuiApplication(argc, _argv);
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment