How do I get a real file name off (QtQuick) FileDialog.fileUrl()?



  • I have an app that asks the user to pick an image from the Pictures folder. It returns an URL which the c++ portion of the code is to use. On the c++ side, I have this (the image picked is named "asset.png"):

    QUrl url(image_returned_from_fileURL);
    QString imageName = url.toLocalFile();
    qDebug() << imageName;
    

    This gets converted to:

    "assets-library://asset/asset.PNG?id=732175CD-BE15-44B6-BC1C-7008F03808A1&ext=PNG"

    How do I get "asset.png" from this?


  • Lifetime Qt Champion

    Hi,

    Something like:

    QString localFile = url.toLocalFile();
    int start = localFile.lastIndexOf("/") + 1;
    int length = localFile.indexOf("?id=") - start;
    QString imageName = localFile.mid(start, length);
    

    ?



  • @SGaist I didn't try it (I'll take a look tomorrow) but this would seem to return just the file name, which I agree is what my question technically asked. What I want to have is a usable path to the file that can be used by standard functions like fopen(). The path /asset/asset.png doesn't work. I don't even know where it gets that name from. If I "mail" the image to myself, I get something named IMG_0133.PNG.

    Thanks!


  • Lifetime Qt Champion

    Ok, what do you need to do with that file ?



  • @SGaist I need to give the file name to a third party library that expects a standard const char* file name.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.