Downloading problem in QML via binding Qt
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
- {
- directory.setCurrent("/sdcard/tmpEpubFile");
- }
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!
8 replies
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…
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 belowBasically you are informing Qml about download finish, and then calling ExtractFile function. try and let us know if this works…
CDownLoadFile{ id:epubdownload onDownloadFinished: { readepubfile.ExtractFile("/sdcard/tmpEpubFile/munroeki3565235652-8epub.epub") } }
it does not work ,thank you
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??
when you say it does not work1) 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??
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!
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.
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.
You are genius,it works ,now after downloading the file ,it operates the extraction
Thanks again!
My best regards!
you are most welcome..
this link helps to teach QtQuick http://doc.qt.nokia.com/4.7/qtquick.html
You must log in to post a reply. Not a member yet? Register here!

