Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Downloading problem in QML via binding Qt

Downloading problem in QML via binding Qt

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 5.6k Views
  • 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.
  • X Offline
    X Offline
    xiazhouquan
    wrote on last edited by
    #1

    Hi,I want to dowload a file via Qt in QML ,after finishing dowloading the file , I deal with it in other function ,this can be described in qml function just like this .

    @
    import CDownLoadFile 1.0
    import CReadEpubFile 1.0
    ...........
    CDownLoadFile{id:epubdownload}
    CReadEpubFile{id:readepubfile}

        function bookClicked() {
        epubdownload.DownloadFile("http://s3.amazonaws.com/manybooksepub/munroeki3565235652-8epub.epub")
        readepubfile.ExtractFile("/sdcard/tmpEpubFile/munroeki3565235652-8epub.epub")
    }
    

    @

    the DownloadFile was implemented in qt like below
    @
    void CDownLoadFile::DownloadFile(QUrl url)
    {
    QDir directory("/sdcard");
    directory.mkdir(QString("tmpEpubFile"));
    directory.setCurrent("/sdcard/tmpEpubFile");
    QFileInfo fileInfo(url.path());
    QString fileName = fileInfo.fileName();
    m_pFile = new QFile(fileName);
    m_pFile->open(QIODevice::WriteOnly);
    m_pManager=new QNetworkAccessManager();
    m_pReply= m_pManager->get(QNetworkRequest(url));
    QObject::connect(m_pReply, SIGNAL(readyRead()),this, SLOT(HttpReadyRead()));
    QObject::connect(m_pReply,SIGNAL(finished()),this,SLOT(HttpFinished()));
    }
    @

    the result is that epubdownload.DownloadFile() and readepubfile.ExtractFile() are at the same time executing ,the file was not completely downloaded ,other operation to the file goes on!

    how can i resolve it!
    Thanks very much!please forgive my poor english!
    my best regards!

    业精于勤荒于嬉,行成于思毁于随

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on last edited by
      #2

      Looks like your HttpFinished() slot is called when download is finished?
      Inside this slot, raise a signal say downloadFinished() and catch it on Qml side like below

      @CDownLoadFile{
      id:epubdownload
      onDownloadFinished: {
      readepubfile.ExtractFile("/sdcard/tmpEpubFile/munroeki3565235652-8epub.epub")
      }
      }@

      Basically you are informing Qml about download finish, and then calling ExtractFile function.
      try and let us know if this works...

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xiazhouquan
        wrote on last edited by
        #3

        [quote author="Vijay Bhaska Reddy" date="1309234316"]Looks like your HttpFinished() slot is called when download is finished? Inside this slot, raise a signal say downloadFinished() and catch it on Qml side like below @CDownLoadFile{ id:epubdownload onDownloadFinished: { readepubfile.ExtractFile("/sdcard/tmpEpubFile/munroeki3565235652-8epub.epub") } }@ Basically you are informing Qml about download finish, and then calling ExtractFile function. try and let us know if this works...[/quote]

        it does not work ,thank you

        业精于勤荒于嬉,行成于思毁于随

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thisisbhaskar
          wrote on last edited by
          #4

          when you say it does not work

          1. Is your HttpFinished() is called as soon as the file download is finished? If this is not working, everything else will fail.
          2. Are you emitting downloadFinished() signal from HttpFinished() ?
          3. Can you place a console.log() inside onDownloadFinished: and see if the control comes inside onDownloadFinished.

          Which one of these steps fail??

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xiazhouquan
            wrote on last edited by
            #5

            [quote author="Vijay Bhaska Reddy" date="1309241695"]when you say it does not work

            1. Is your HttpFinished() is called as soon as the file download is finished? If this is not working, everything else will fail.
            2. Are you emitting downloadFinished() signal from HttpFinished() ?
            3. Can you place a console.log() inside onDownloadFinished: and see if the control comes inside onDownloadFinished.

            Which one of these steps fail??
            [/quote]

            Thank you for reply,I think that is not the steps above,here is my HttpFinished() function
            @
            void CDownLoadFile::HttpFinished()
            {
            m_pFile->flush();
            m_pFile->close();
            m_pReply->deleteLater();
            m_pReply = 0;
            delete m_pFile;
            m_pFile = 0;
            emit DownloadFinished();
            }
            @
            the signal was defined in the header file ,just like
            @
            signals:
            Q_INVOKABLE void DownloadFinished();
            @

            In the qml file ,I invoke the signal like this
            @
            CDownLoadFile{
            id:epubdownload
            onDownloadFinished: {
            readepubfile.ExtractFile("/sdcard/tmpEpubFile/munroeki3565235652-8epub.epub")
            }
            }
            @
            The Qt creator shows that onDownloadFinished is not a valid property name,when I run the project ,the console shows that qrc:/qml/Reader/DelegateGrid.qml:13:9: Cannot assign to non-existent property "onDownloadFinished" .
            why it happens!
            thank you again!

            业精于勤荒于嬉,行成于思毁于随

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thisisbhaskar
              wrote on last edited by
              #6

              couple of syntax mistakes...

              1. Name of signal should be "downloadFinished" ( should start with small letter).
              2. Don't need Q_INVOKABLE in-front of "void downloadFinished()". Remove it.

              now keep everything else same and compile the code and see if it works.

              PS: signal downloadFinished() automatically generates a slot called onDownloadFinished() in the qml side.

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xiazhouquan
                wrote on last edited by
                #7

                [quote author="Vijay Bhaska Reddy" date="1309253856"]couple of syntax mistakes...

                1. Name of signal should be "downloadFinished" ( should start with small letter).
                2. Don't need Q_INVOKABLE in-front of "void downloadFinished()". Remove it.

                now keep everything else same and compile the code and see if it works.

                PS: signal downloadFinished() automatically generates a slot called onDownloadFinished() in the qml side.
                [/quote]

                You are genius,it works ,now after downloading the file ,it operates the extraction
                Thanks again!
                My best regards!

                业精于勤荒于嬉,行成于思毁于随

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  thisisbhaskar
                  wrote on last edited by
                  #8

                  you are most welcome..
                  this link helps to teach QtQuick http://doc.qt.nokia.com/4.7/qtquick.html

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    gurpal2000
                    wrote on last edited by
                    #9

                    Hi all - newbie here. How does the above solution deal with large files? I read somewhere else that reading the source in chunks and also writing in chunks is better on memory? For example 10MB, 100MB, 1GB, 4GB sizes?

                    How would the above code change (if at all?).

                    thanks

                    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