2

I want to implement an application for iOS. I’ve used Qt 5.3 on Mac. I want to defined user interface in Qt. I want to have a button on *.ui. When clicking on that, iOS photo library will be opened and then user can be able to select a photo. I know that I must use UIImagePickerController.

I have to use the root controller and show the UIPickerImageController on that. For doing so, I need to use some internal Qt API:

first, in the *.pro:

QT += gui-private

then, in my *.mm code get the pointer to the root view controller of the Qt app:

UIView *view = static_cast<UIView *>( QGuiApplication::platformNativeInterface()->nativeResourceForWindow("uiview",quickView) );
UIViewController* rootCtrl = [[view window] rootViewController];

and now, I can show the UIImagePickeController:

[rootCtrl presentViewController:imagePickerController animated:YES completation:nil]

this way to get the root view controller with QML, solved my problem but I don’t want to use QML. Is there another way to get a pointer to the main root view controller of the Qt application(C++ + Objective-C) without using QML?

Thanks!

Iuliu
  • 4,001
  • 19
  • 31
Hasti Ranjkesh
  • 643
  • 10
  • 26

1 Answers1

3

You can use UIApplication and keyWindow property:

UIViewController* rootViewController = [[UIApplication sharedApplication].keyWindow rootViewController];
Andrew Romanov
  • 4,774
  • 3
  • 25
  • 40