Abdeljalil
18th October 2014, 15:04
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 QLineEdit
some code:
downloadData function in QHashCracker class:
void QHashCracker::downloadData()
{
manager = new QNetworkAccessManager(this);
QObject::connect(manager,SIGNAL(finished(QNetworkR eply*)),
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.
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 QLineEdit
some code:
downloadData function in QHashCracker class:
void QHashCracker::downloadData()
{
manager = new QNetworkAccessManager(this);
QObject::connect(manager,SIGNAL(finished(QNetworkR eply*)),
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.