Downloading data from nseindia

  • Hi Experts ,

    I am downloading data from
    and the link is ""

    But i am downloading 0 size file ..

    anything wrong ? or any working program for downloading files from web?

    @downloader::downloader(QObject *parent) :



    void downloader::downloadFile(const QString &url, const QString &aPathInClient)

    QNetworkAccessManager m_NetworkMngr;
    QNetworkReply *reply= m_NetworkMngr.get(QNetworkRequest(url));
    QEventLoop loop;
    QObject::connect(reply, SIGNAL(finished()),&loop, SLOT(quit()));
    QUrl aUrl(url);
    QFileInfo fileInfo=aUrl.path();
    QFile file(aPathInClient+"\\"+fileInfo.fileName());;
    delete reply;

    void downloader::myprocedure()

    QString path;
    QString localpath;
    QMessageBox msgBox;
    QMessageBox msgBox2;
    path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
    path = "C:/Users/ryerajan/build-untitled2-Desktop_Qt_5_3_MinGW_32bit-Debug/base/download/";
    localpath = path;

    // QMessageBox msgBox2;
    msgBox2.setText("You can download the update from the web.");
    msgBox2.setInformativeText("Do you want to download the file now?");
    msgBox2.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    int ret = msgBox2.exec();

    if (ret == QMessageBox::Yes) {
        downloadFile ("", localpath);
        msgBox.setText("Your file should be updated now");
    else {
        // Do something else


  • Moderators

    You can use Q_FUNC_INFO instead of FILE<<" : " << FUNCTION . It is less to type :-)

  • Hi I updated the post.... help me .. how can i download from website a ZIP or any file..... any working program for windows, qt

  • Moderators

    Your code has many small issues:

    • you are not checking QNetworkReply for errors
    • you are not checking if QFile::open() was successful
    • you are using \ as the delimiter instead of / (Qt uses Unix paths internally)
    • you are passing a full file name to downloadFile() method, but you then append another file name using fileInfo.path(). I seriously doubt that fileInfo is not a valid path, because you try to create it from a QUrl. Please check the path and verify that it is correct
    • you are deleting the QNetworkReply object instead of calling deleteLater()
    • you do not check whether the QNetworkReply actually has any data

    I suggest running this code through a debugger and going step by step to see what is happening.

  • Moderators


    It seems that you are not closing the file.

  • Moderators

    [quote author="p3c0" date="1421151089"]Hi,

    It seems that you are not closing the file.[/quote]

    This is not required when using QFile created on a stack.

    NOTE: I've moved your post, p3c0, to this thread because the OP has double-posted.

  • Eureka,
    Its working ....
    i have added the header fields with user-agent, host, accept-agent ..etc fileds
    Thanks to everyone.

Log in to reply

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