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]UIImagePickerController in qt
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]UIImagePickerController in qt

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 3 Posters 3.3k 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

    I asked this question a few days ago : "click here":http://qt-project.org/forums/viewthread/48678/
    and someone suggested to me to use a qml approach.
    I did and it works.
    But i want to know is there another solution without qml? I don't want to use qml in my application. I want to use only cpp code in qt5.3 plus native ios code (objective c). Is there any way for that?
    I want to use objective c UIImagePickerController in qt to open ios photo library and pick an image.
    thanks in advance...

    Hasti Ranjkesh

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

      I already answered to your question and I didn't suggest you to use QML ... where I did ?!?!

      Again, your problem on using the UIImagePickerController is that you have to get a pointer to the main root view controller of the Qt application. This is done via the gui-private headers.

      In the answer of the post you cited, I write one way to get the root view controller and solve your problem.

      If my solution was not suitable for your case, you should had replied in the other post, and not to open another one.
      And if my solution works, then you should mark the topic as solved so other people can use it instead of open topics.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hasti66
        wrote on last edited by
        #3

        Hi Gianluca and thank. I'm sorry, you are right. But still i want to know how can i get a pointer to the main root view controller of the Qt application(cpp + objective c) via the gui-private headers? You wrote one way to get the root view controller and solve my problem but i don't want to use qml.
        thank you very much

        Hasti Ranjkesh

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

          Until Qt will not made a public API to get the root view controller, your only alternative is to dig into the private headers and look for a suitable method to get the root view controller.
          This is an online link to the source code: https://qt.gitorious.org/qt/qtbase/source/32c517c9906962a15f214cdcab1d57b32cc8a7e8:src/gui/kernel/qplatformnativeinterface.h

          If you look to the header, you will note that there is a method called nativeResourceForBackingStore that has almost the same signature of the nativeResourceForWindow, so I suppose that works in the same way but it need a pointer to a QBackingStore.
          You can get a pointer to QBackingStore from your root QWidget.

          Give a try, and please mark as solved the topics if the solution works.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hasti66
            wrote on last edited by
            #5

            I finally found a way to use UIImagePickerController from qt5.3 on mac, without using qml. I created a subclass of UIViewController in .mm file and defined a method (called openiOSPhotoLibrary) in it to implement an UIImagePickerController. Then i created a cpp bridge method in the .mm file to call that method.
            Thanks

            Hasti Ranjkesh

            1 Reply Last reply
            0
            • patrikdP Offline
              patrikdP Offline
              patrikd
              wrote on last edited by
              #6

              hi hasti66,
              I'm currently on the same problem. could you maybe please post the code for the cpp bridge which starts the uiviewcontroller.
              thx,
              patrik

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hasti66
                wrote on last edited by
                #7

                Hi, here is code:
                //in mainwindow.h
                @
                class MainWindow : public QMainWindow
                {
                Q_OBJECT

                public:
                ...
                void bridgeMethodToCallObjectiveC(int , MainWindow *);
                ...
                };
                @

                //in .mm file
                @
                void MainWindow::bridgeMethodToCallObjectiveC(int fileType , MainWindow *mainwindow)
                {
                void *context = [[photoPickerDelegate alloc] init];
                [(id) context openPhotoLibraryObjC:fileType];
                }

                • (void)openPhotoLibraryObjC:(int)fileType
                  {
                  window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
                  [window setRootViewController:self];
                  [window makeKeyAndVisible];

                  UIImagePickerController *imageController = [[[UIImagePickerController alloc] init] autorelease];
                  imageController.delegate = self;
                  [imageController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
                  imageController.allowsEditing = NO;

                  //pick video
                  if(fileType ==2)
                  imageController.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie , nil];

                  [self presentViewController:imageController animated:YES completion:NULL];

                }
                @

                Good luck

                Hasti Ranjkesh

                1 Reply Last reply
                0
                • patrikdP Offline
                  patrikdP Offline
                  patrikd
                  wrote on last edited by
                  #8

                  Hi hasti,
                  thx very much :) you call the "bridgeMethodToCallObjectiveC" from your qt code!? what do you take as the window param?
                  best,
                  patrik

                  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