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. How do I get a real file name off (QtQuick) FileDialog.fileUrl()?

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

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 2 Posters 1.5k Views 2 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.
  • D Offline
    D Offline
    Dogmaphobic
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Something like:

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

      ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Something like:

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

        ?

        D Offline
        D Offline
        Dogmaphobic
        wrote on last edited by
        #3

        @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!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply
          0
          • SGaistS SGaist

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

            D Offline
            D Offline
            Dogmaphobic
            wrote on last edited by
            #5

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

            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