[SOLVED] Update GUI after gettings network result from second class.
i have Widget class and another class called QHashCracker.
Hash cracking class uses QNetworkAccessManager to get a result from the internet in Json format and parse it and set the result to class member called reply (of type QString)
HashCracker have a slot called
that is connected to
signal from QNetworkAccessManager.
and a downloadData() function that connects signals and slots and set QNetworkRequest to the manager.
now after i created a QHashCracker object in the Widget class and run downloadData() in a QPushButton click slot.
this should download the data, parse Json and set the value i need to "reply" member. but after that i want to set the result to QLineEdit in the ui.
here is the problem
network operations needs some time, i tried QTest::qSleep(2000) to pause program execution after downloadData() runs, then show the result in QLineEdit
downloadData function in QHashCracker class:
manager = new QNetworkAccessManager(this);
replyFinished slot in QHashCracker class:
void QHashCracker::replyFinished(QNetworkReply *reply)
//qDebug() << reply->readAll();
QJsonDocument replyDocument = QJsonDocument::fromJson(reply->readAll());
QJsonObject DocumentObj = replyDocument.object();
QJsonValue ParsingValue = DocumentObj.value("parsed");
this->reply = ParsingValue.toString();
qDebug() << this->reply;
on_crack_pushButton_clicked() function in Widget class:
hashCracker = new QHashCracker(ui->md5crack_lineEdit->text());
i hope this is clear.
There are couple of ways to do it.
The best way would be to emit a signal with the output data from QHashCracker::replyFinished function which is connected to a slot in
Widget class. And in this slot you receive the output data and set it to the lineedit.
thank you a lot
it's working :)