[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
@replyFinishied(QNetworkReply*)@
that is connected to
@finished(QNetworkReply*)@
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 QLineEditsome code:
downloadData function in QHashCracker class:
@
void QHashCracker::downloadData()
{
manager = new QNetworkAccessManager(this);
QObject::connect(manager,SIGNAL(finished(QNetworkReply*)),
this,SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl(this->request)));
}
@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:
@
void Widget::on_crack_pushButton_clicked()
{
hashCracker = new QHashCracker(ui->md5crack_lineEdit->text());
hashCracker->downloadData();
QTest::qSleep(1000);
ui->md5cracked_lineEdit->setText(hashCracker->getReply());
}
@i hope this is clear.
-
Hi,
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 :)