Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] Use ios UIImagePickerController to picking a photo in qt5.3
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Use ios UIImagePickerController to picking a photo in qt5.3

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 4.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hasti66
    wrote on last edited by
    #1

    Hi, I want to implement an application for ios. I've used qt5.3 on mac. I want to defined user interface in qt. I want to have a button on ui. when cliking 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. but always i get this error and photo library is not opened.
    this error:
    Warning: Attempt to present <UIImagePickerController: 0xa8c4520> on <APLViewController: 0xa9eaa90> whose view is not in the window hierarchy!

    here is my code:
    //.mm file

    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <Foundation/NSString.h>

    #import "mainwindow.h"
    #include <QDebug>

    @interface APLViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
    {
    }
    @property (nonatomic) UIImagePickerController *imagePickerController;
    @end

    @implementation APLViewController
    MainWindow *mWindowInstance;

    • (int)showImagePickerForPhotoPicker:(MainWindow *)myInstance
      {
      myInstance->text->append("showImagePickerForPhotoPicker");
      [self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

      return 5;
      }

    • (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
      {
      NSLog(@"start of showImagePickerForSourceType");

      UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
      imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
      imagePickerController.sourceType = sourceType;
      imagePickerController.delegate = (id)self;

      self.imagePickerController = imagePickerController;
      [self presentViewController:self.imagePickerController animated:YES completion:nil];

      NSLog(@"end of showImagePickerForSourceType");
      }

    // This method is called when an image has been chosen from the library or taken from the camera.

    • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
      {
      UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
      [self finishAndUpdate];
      }

    • (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
      {
      [self dismissViewControllerAnimated:YES completion:NULL];
      }

    void MainWindow::bridgeMethod(void*context, MainWindow *qIns)
    {
    mWindowInstance = qIns;
    context = [[APLViewController alloc] init];
    [(id) context showImagePickerForPhotoPicker:qIns];
    }

    @end

    I know the problem is in this line:
    [self presentViewController:self.imagePickerController animated:YES completion:nil];
    how can i handle that? please help me
    Thanks in advance...

    Hasti Ranjkesh

    1 Reply Last reply
    0
    • GianlucaG Offline
      GianlucaG Offline
      Gianluca
      wrote on last edited by
      #2

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

      • first, in the .pro declare you want to use private headers:
        @
        QT += gui-private
        @
      • then, in your .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, you can show the UIImagePickeController:
        @
        [rootCtrl presentViewController:imagePickerController animated:YES completation:nil]
        @
      1 Reply Last reply
      0
      • H Offline
        H Offline
        hasti66
        wrote on last edited by
        #3

        thank you very much. I will try with your guide.

        Hasti Ranjkesh

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved