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. getting movie file path on ios from gallery

getting movie file path on ios from gallery

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 265 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.
  • M Offline
    M Offline
    Marek
    wrote on last edited by
    #1

    Hi
    I have posted this question on stackoverflow, but no luck so far. link
    I can't select movie on iOS with Qt, when I use FIleDialog it opens dialog but not for movies but other directories, even if I set folder: shortcuts.movies
    So I have opened native UIImagePicker but don't know how to get the result from function in .m file, had I had result in Objective-C++ (.mm) file then I could use my Singleton to communicate with the rest of my app, but inside .m file I can't. Can somebody help? Since there is no Qt way to do it, solving this might by also useful for others.
    My files:
    CL_image_call.mm - static functions that I'm calling from inside Qt classes

    #include "cl_image_call.h"
    #include "cl_image_func.h"
    
    myCLImageClass* CL_image_obj=NULL;
    
    int CL_ImageCCall::CL_objectiveC_Call() {
      //Objective C code calling..... 
        if( CL_image_obj==NULL ) {
          //Allocating the new object for the objective C class we created
            CL_image_obj=[[myCLImageClass alloc]init]; 
        }
      return 1;
    }
    void CL_ImageCCall::CL_openMedia() {
        [CL_image_obj openMedia];
    }
    

    CL_image_call.h - header for static class

    #include <QImage>
    #include <QString>
    #include <QDebug>
    #include <stdio.h>
    #include "my_singleton.h"
    
    class CL_ImageCCall
    {
      public:
        static int CL_objectiveC_Call(); 
        static void CL_openMedia();  
    };
    

    CL_image_func.h - header for .m file

    #import <Foundation/Foundation.h>
    #import <CoreLocation/CoreLocation.h>
    #import <CoreGraphics/CoreGraphics.h>
    #import <UIKit/UIKit.h>
    #import <MobileCoreServices/MobileCoreServices.h>
    
    @interface myCLImageClass:NSObject
    -(void)openMedia;
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
    @end
    

    CL_image_func.m - here I open UIImagePicker and get the selected filePath (this is what I need)

    #import "cl_image_func.h"
    
    @interface QIOSViewController : UIViewController
    @end
    
    @implementation myCLImageClass
    UIImagePickerController *picker=NULL;
    UIViewController *viewController=NULL;
    NSString *f_path;
    
    -(void)openMedia {
        UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
        
        viewController = (UIViewController *)([keyWindow rootViewController]);
            if (!viewController)
                return;
        
        if([UIImagePickerController isSourceTypeAvailable:
                                UIImagePickerControllerSourceTypePhotoLibrary]) {
    
             picker= [[UIImagePickerController alloc] init];
             picker.delegate = self;
             picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
             picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];
    
             [viewController presentViewController:picker animated:YES completion:NULL];
        }
    }
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
        NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *filePath =  [docDirPath stringByAppendingPathComponent:@"movie.mov"];
        NSLog (@"File Path = %@", filePath);
        //filePath is what I need to pass to the rest of my app
        
        [viewController dismissViewControllerAnimated:YES completion:nil];
    }
    

    Best Regards
    Marek

    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