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 c++
Forum Updated to NodeBB v4.3 + New Features

QT c++

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.1k 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.
  • S Offline
    S Offline
    shashi prasad
    wrote on last edited by SGaist
    #1

    Hi All,
    using below code for downloading.

    string recBuff = Download(wpathURL.c_str());
    
    Download(std::wstring szUrl){
    
    connect(&manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(downloadFinished(QNetworkReply*)));
      QString url("http://guest:p2guest@192.168.55.3/contents/2/clip/08615L.xml");
      QUrl urls(url);
      QNetworkRequest request(urls);
      manager.get(request);
    
    }
    
    downloadFinished(QNetworkReply *data) {
      QFile localFile("/home/roi/Desktop/downloadedfile.txt");
      if (!localFile.open(QIODevice::WriteOnly))
          return;
      const QByteArray sdata = data->readAll();
      localFile.write(sdata);
      qDebug() << sdata;
      localFile.close();
    
    }
    

    issue is control does not goes to sloats downloadFinished.

    file which i want to download is small and network is connected.

    so please suggest me why it is not going to sloats.

    Thanks
    shashi

    [edit: added coding tags SGaist]

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

      Hi,

      Your code as is, won't even compile so it can't be accurately analysed for bugs.

      You should also connect the error signal related signals to see if there's anything going wrong.

      And please use the coding tags to enclose your code so it makes it more easily readable. It's three back ticks or use the last button that is just above the text edit area.

      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
      • S Offline
        S Offline
        shashi prasad
        wrote on last edited by
        #3

        Hi
        This code compiles properly.

        string recBuff = Download(wpathURL.c_str());

        Download(std::wstring szUrl){
        char data;
        connect(&manager, SIGNAL(finished(QNetworkReply
        )),this, SLOT(downloadFinished(QNetworkReply*)));
        QString url("http://guest:p2guest@192.168.55.3/contents/2/clip/08615L.xml");
        QUrl urls(url);
        QNetworkRequest request(urls);
        manager.get(request);
        return data;
        }

        downloadFinished(QNetworkReply *data) {
        QFile localFile("/home/roi/Desktop/downloadedfile.txt");
        if (!localFile.open(QIODevice::WriteOnly))
        return;
        const QByteArray sdata = data->readAll();
        localFile.write(sdata);
        qDebug() << sdata;
        localFile.close();

        }

        please suggest now.

        Ni.SumiN 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Maybe for you, but I don't see any class declaration nor any Q_OBJECT macro nor any return type for your functions and you haven't even added the error detection I suggested.
          Your SIGNAL macro content is wrong thus your connection will fail at runtime. If using Qt 5, change for the new connection syntax and you'll have a build time error.

          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
          4
          • S shashi prasad

            Hi
            This code compiles properly.

            string recBuff = Download(wpathURL.c_str());

            Download(std::wstring szUrl){
            char data;
            connect(&manager, SIGNAL(finished(QNetworkReply
            )),this, SLOT(downloadFinished(QNetworkReply*)));
            QString url("http://guest:p2guest@192.168.55.3/contents/2/clip/08615L.xml");
            QUrl urls(url);
            QNetworkRequest request(urls);
            manager.get(request);
            return data;
            }

            downloadFinished(QNetworkReply *data) {
            QFile localFile("/home/roi/Desktop/downloadedfile.txt");
            if (!localFile.open(QIODevice::WriteOnly))
            return;
            const QByteArray sdata = data->readAll();
            localFile.write(sdata);
            qDebug() << sdata;
            localFile.close();

            }

            please suggest now.

            Ni.SumiN Offline
            Ni.SumiN Offline
            Ni.Sumi
            wrote on last edited by Ni.Sumi
            #5

            @shashi-prasad

            Seems , This code is from the Qt examples. You have copied as it is in the example and did not make changes needed .
            I am expecting all the code in Qt class with Q_OBJECT as it is in the sample.

            • you have copied the main() code simply in to your own function directly. Which is not preferable. You need some code like inside your function.
            void MainWindow::startQtDownload(QString stg ) {
            QtDownload *dl = new QtDownload;
            dl->setTarget(stg);
            dl->download();
            qDebug() << "Got clicked _2";
            qDebug() << "MainWindow" << QObject::connect(dl, SIGNAL(done()), this, SLOT(closeit())); //This is Qt 4.8  way, better use Qt5  way connect()
            }
            
            • Also as Mr. @SGaist sugguested , the connect is not placed / coded properly. It not should be placed inside this function. Download(std::wstring szUrl) . Please be as it is in constructor of the QtDownlaod class.

            • Currently in that there is nothing to give error messages. Please make some code to look for errors, so that it would be easy to catch the errors.

            Here I have attached small sample of your code and called the QtDownlaod class in MainWindow class. I made a zip , download it and use it as you like.

            https://www.dropbox.com/s/k9cc3fcaadph8br/forumNetworkExample.zip?dl=0

            Hopefully, this will solve your problem.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved