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. Downloading data from nseindia
Forum Updated to NodeBB v4.3 + New Features

Downloading data from nseindia

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

    Hi Experts ,

    I am downloading data from www.nseinda.com
    and the link is "http://www.nseindia.com/content/historical/EQUITIES/2015/JAN/cm12JAN2015bhav.csv.zip"

    But i am downloading 0 size file ..

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

    @downloader::downloader(QObject *parent) :
    QObject(parent)
    {

    myprocedure();
    

    }

    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()));
    loop.exec();
    QUrl aUrl(url);
    QFileInfo fileInfo=aUrl.path();
    
    QFile file(aPathInClient+"\\"+fileInfo.fileName());
    file.open(QIODevice::WriteOnly);
    file.write(reply->readAll());
    
    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/cm01OCT2014bhav.dbf.zip";
    
    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);
    msgBox2.setDefaultButton(QMessageBox::Yes);
    int ret = msgBox2.exec();

    if (ret == QMessageBox::Yes) {
    
        downloadFile ("http://www.nseindia.com/content/historical/EQUITIES/2014/OCT/cm01OCT2014bhav.dbf.zip", localpath);
    
        msgBox.setText("Your file should be updated now");
        msgBox.exec();
    
    }
    
    else {
    
        // Do something else
    
    }
    

    }@

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

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

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rambabuy
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.

          (Z(:^

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            Hi,

            It seems that you are not closing the file.

            157

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              [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.

              (Z(:^

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rambabuy
                wrote on last edited by
                #7

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

                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