PDA

View Full Version : QNetworkAccessManager & QML Progress



scgrant327
25th March 2016, 13:06
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*)),t his,SLOT(erroron_filesend(QNetworkReply*)));
connect(manager, SIGNAL(uploadProgress(qint64 uplPart, qint64 uplTotal)), SLOT(progressChanged(qint64 uplPart, qint64 uplTotal)));


In my main.qml, tried to declare a local variant to hold a reference to the Manager:



property variant networkAccess


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);
}
}


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

anda_skoa
25th March 2016, 14:16
You QML Code looks like you have an object that is exposed to QML as "appWin" through the setContextProperty mechanism.
And it has a property of a QObject type, with a signal processChanged() which has arguments named "uplTotal" and "uplPart".

Can you confirm that?
Maybe even post the relevant code?

No idea why you need that variant property though, something unrelated to this?

Cheers,
_