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

File download - How to open the file?



  • Hi,

    I am trying to download the file from the server through QML. I created an file called abc.tpk and map the path for file response.But I am getting an error stating:

    additionalMessage: The file path to the response file could not be opened.

    Query: Do we need to pen the file through QML like file.open in CPP. If it is the case, how to open the file in QML.

     QString filenamep = "Prefecture.tpk";
     QFile file(filenamep);
    
     file.open(QIODevice::WriteOnly);
     if(!file.open(QIODevice::WriteOnly))
     {
    
     }
    QString strUrl="http://testser/home/item.html?id=83d1c9aaf9d04e60bda3e822f25a8c67";
       QUrl url = QUrl::fromUserInput(strUrl);
    
       QFileInfo fileInfo(url.path());
      // QString strhost = url.encodedHost();
       QString filename = fileInfo.fileName();
    
       file.setFileName("C:\\Qt\\QHttp\\"+filename);
       http.setHost(url.host(),url.port(80));
       http.get(url.path(),&file);
    
    
       file.write(http.readAll());
       http.close();
    
        file.close();
    


  • Hi @Mathan-M,

    With QML you can use Qt.openUrlExternally(/path/to/my/file/myFile) to open an file with the default program.
    More informations here.

    Bye

    Charlie


Log in to reply