I am trying to use QNetworkAccessManger to upload a file and show progress. I have the upload portion working excellently. I cannot seem to get the Progress portion working.
I have a QML ProgressBar on one screen of my mobile app. I tried setting up a Signal like so:
QNetworkAccessManager *manager = new QNetworkAccessManager(this); //using qnetwork access manager for post data
QObject *root
= engine.
rootObjects().
first();
root->setProperty("networkAccess",manager);
manager->post(req,datas); //send all data
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(erroron_filesend(QNetworkReply*)));
connect(manager, SIGNAL(uploadProgress(qint64 uplPart, qint64 uplTotal)), SLOT(progressChanged(qint64 uplPart, qint64 uplTotal)));
QNetworkAccessManager *manager = new QNetworkAccessManager(this); //using qnetwork access manager for post data
QObject *root = engine.rootObjects().first();
root->setProperty("networkAccess",manager);
manager->post(req,datas); //send all data
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(erroron_filesend(QNetworkReply*)));
connect(manager, SIGNAL(uploadProgress(qint64 uplPart, qint64 uplTotal)), SLOT(progressChanged(qint64 uplPart, qint64 uplTotal)));
To copy to clipboard, switch view to plain text mode
In my main.qml, tried to declare a local variant to hold a reference to the Manager:
property variant networkAccess
property variant networkAccess
To copy to clipboard, switch view to plain text mode
Then in the QML with the ProgressBar I did this:
ProgressBar {
id: fileUplProgress
visible: false
anchors.top: busyLabel.bottom
anchors.topMargin: Funcs.psize(10,parent.height)
anchors.horizontalCenter: parent.horizontalCenter
width: Funcs.psize(50,parent.width)
height: Funcs.psize(5,parent.hight)
minimumValue: 0.0
maximumValue: 100.0
}
Connections {
target: appWin.networkAccess
onProgressChanged: {
fileUplProgress.value = 100*uplTotal/uplPart;
console.log(qsTr("Progress %1").arg(100*uplTotal/uplPart);
}
}
ProgressBar {
id: fileUplProgress
visible: false
anchors.top: busyLabel.bottom
anchors.topMargin: Funcs.psize(10,parent.height)
anchors.horizontalCenter: parent.horizontalCenter
width: Funcs.psize(50,parent.width)
height: Funcs.psize(5,parent.hight)
minimumValue: 0.0
maximumValue: 100.0
}
Connections {
target: appWin.networkAccess
onProgressChanged: {
fileUplProgress.value = 100*uplTotal/uplPart;
console.log(qsTr("Progress %1").arg(100*uplTotal/uplPart);
}
}
To copy to clipboard, switch view to plain text mode
First error I get is with declaring the variant for the Manager in the qml. I have other variants that hold strings passed from C++, so I know it works.
In short, what is the best way to upload a file in C++ and get the progress in my QML page?
--Sam
Bookmarks