Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QImage + iOS open from locale path



  • Hello, I'm write application for iOS. I get image path via QML FileDialog ("file:assets-library://asset/asset.JPG%3Fid=C6E6...77E9&ext=JPG")) and send to C++, I get message "Image not load". what I do wrong ?
    qml:

        FileDialog {
            id: fileDialog
            title: "Please choose a file"
            folder:StandardPaths.standardLocations(StandardPaths.PicturesLocation)[2]//shortcuts.home
            selectExisting: true
            onAccepted: {
                //console.log(file)
                imageProcessor.processImage_file(fileDialog.file)
                fileDialog.close()
            }
            onRejected: {
                console.log("Canceled")
                fileDialog.close()
            }
        }
    

    C++:

    void ImageProcessor::processImage_file(const QString &path)
    {
        QString assetsPath=path;
        QImage myImage;
        QUrl url(assetsPath);
        assetsPath = url.toLocalFile();
        myImage.load(assetsPath);
        if( !myImage.isNull()) 
        {
                  //........
        }
        else qDebug()<<"Image not load";
    


  • I have same issue, I used Filedialog as below:

     FileDialog {
                                id: fileOpenDialog
    
                                title: "Select an image file"
                                folder: Qt.platform.os == "ios" ? shortcuts.pictures :shortcuts.documents
                                nameFilters: [ "Image files (*.png *.jpeg *.jpg)" ]
                                onAccepted: {
                                    console.log(fileOpenDialog.fileUrl);
                                    avatar.source = fileOpenDialog.fileUrl;
                              }                               
    }
    

    But when I try to choose an image from iOS device, the path is
    qml: file:assets-library://asset/asset.HEIC%3Fid=CC95F08C-88C3-4012-9D6D-64A413D254B3&ext=HEIC
    Then I can't open it in Image as set avatar.source = fileOpenDialog.fileUrl;
    Anyone have solution?



  • Then I try get a PNG file instead HEIC, but I still got error, and there is a strange thing, this is my log:

    qml: file:assets-library://asset/asset.PNG%3Fid=C8465D9C-B920-4400-9C92-2B34ADD5127C&ext=PNG
    qrc:/pages/UserInfoPopUp.qml:156:21: QML Image: Error decoding: file:assets-library://asset/asset@3x.PNG%3Fid=C8465D9C-B920-4400-9C92-2B34ADD5127C&ext=PNG: Unsupported image format
    

    I don't know why as log, I passed asset.PNG but actually image got asset@3x.PNG
    Anyone has idea and solution for these?



  • More information about environment:
    Qt 5.14.0
    Xcode 11.3.1
    iOS simulator: iPhone 6 13.3
    up....


Log in to reply