Results 1 to 4 of 4

Thread: Convert HTTP QUrl to file path on the server

  1. #1
    Join Date
    Jan 2014
    Posts
    76
    Thanks
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Convert HTTP QUrl to file path on the server

    Maybe someone know how I can get relative to specific folder file path from url for example

    from
    "http://doc.qt.io/documents/readme.txt"
    get only
    documents/readme.txt
    without first slash "/"

    from
    "/video/Qt/example.avi"
    get only
    video/Qt/example.avi
    without first slash "/"

    I get several form of url from client applications but I need from that only file path without first "/" because then I can easily doing something like

    Qt Code:
    1. QFileInfo(path).lastModified();
    To copy to clipboard, switch view to plain text mode 

    How I can parse url for this format?

    This statement

    Qt Code:
    1. QFileInfo(url2.path()).filePath();
    To copy to clipboard, switch view to plain text mode 

    return file path but always with first slash "/", so then I need to remove it

    Qt Code:
    1. path.remove(0, 1);
    To copy to clipboard, switch view to plain text mode 

    It is a good solution? Or maybe QUrl have some better way?

    Thanks,

  2. #2
    Join Date
    Oct 2015
    Posts
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Convert HTTP QUrl to file path on the server

    QString was not meant for a canonical url representation. It is a string class existing mostly due to the utf use cases.
    What you are looking for is QUrl which was meant for use cases like this. Pass your path to that, and then get the "QFile-readable" path out of that, then pass it to QFile.

  3. #3
    Join Date
    Jan 2014
    Posts
    76
    Thanks
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Convert HTTP QUrl to file path on the server

    This code solved my problem

    Qt Code:
    1. QString path = QFileInfo(url.path()).filePath();
    2. qDebug()<< QDir("/").relativeFilePath(path);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2015
    Posts
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Convert HTTP QUrl to file path on the server

    QString was not meant for a canonical url representation. It is a string class existing mostly due to the utf use cases. What you are looking for is QUrl which was meant for use cases like this. Pass your path to that, and then get the "QFile-readable" path out of that, then pass it to QFile.

Similar Threads

  1. Replies: 13
    Last Post: 29th May 2015, 05:30
  2. Upload file to HTTP server
    By produktdotestow in forum Qt Programming
    Replies: 5
    Last Post: 30th July 2011, 15:18
  3. How to upload file to HTTP server (POST Method)
    By Alex Snet in forum Qt Programming
    Replies: 8
    Last Post: 24th January 2011, 23:49
  4. mutithread in http-server
    By chuengchuenghq in forum Qt Programming
    Replies: 1
    Last Post: 8th June 2008, 01:24
  5. Build an HTTP server
    By the_bis in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2007, 08:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.