Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt 4.8.4 how to check if file exists on http server

Qt 4.8.4 how to check if file exists on http server

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.3k 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.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    need to check the if file exists on http server, i have the full path and when i try it via browser all works but when i try in code to do :

    @if(QFile::exists("http://www.foo.com/hidden/Support/myapp_1.1.2_installer.exe" ))
    {
    qDebug("file exists");
    return true;
    }
    else
    {
    qDebug("file not exists");
    }@

    as it writen here :
    "Your text to link here...":http://www.qtcentre.org/archive/index.php/t-43712.html?s=b9ae49962c9219aec93b43c514e2ba33

    it allways returns me false no matter what .. what im doing wrong and is it the right way to do this ?

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

      Hi,

      No it's not the right way, QFile is not designed for this purpose, it's for local files. You should rather look into QNetworkAccessManager for what you want to achieve

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        devitt
        wrote on last edited by
        #3

        try using HEAD method

        @bool fileExist(const QUrl &url)
        {
        QTcpSocket socket;
        socket.connectToHost(url.host(), 80);
        if (socket.waitForConnected()) {
        socket.write("HEAD " + url.path().toUtf8() + " HTTP/1.1\r\n"
        "Host: " + url.host().toUtf8() + "\r\n"
        "\r\n");
        if (socket.waitForReadyRead()) {
        QByteArray bytes = socket.readAll();
        if (bytes.contains("200 OK"))
        return true;
        }
        }
        return false;
        }@

        @qDebug() << fileExist(QUrl("http://www.foo.com/hidden/Support/myapp_1.1.2_installer.exe"));@

        1 Reply Last reply
        0
        • U Offline
          U Offline
          umen242
          wrote on last edited by
          #4

          Thanks! working great !

          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