Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Update GUI after gettings network result from second class.
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Update GUI after gettings network result from second class.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abdeljalil
    wrote on last edited by
    #1

    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(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.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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.

      157

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Abdeljalil
        wrote on last edited by
        #3

        thank you a lot
        it's working :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved