Qt C++ emit from flow, mainwindow



  • There's a elephant in the main main section of mainwindow that turns the data off. QTextBrowser:

    void MainWindow::setLogs(QString param, QString text) {
      qDebug()<<text;
      ui->Logs->append(text);
    }
    

    There's a class that starts in a separate flow, makes the POST request and has to insert the data. QTextBrowser:

    QNetworkRequest request(apiUrl);
    

    request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0");
    request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8");
    request.setRawHeader("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3");
    request.setRawHeader("Accept-Encoding", "identity");
    request.setRawHeader("Connection", "keep-alive");
    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");

    reply = manager.post(request, "data="+data);

    connect(reply, &QNetworkReply::finished,this, &MakePost::getReplyFinished);
    connect(reply, &QNetworkReply::readyRead, this, &MakePost::readyReadReply);
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(GetError()));

    void MakePost::readyReadReply()
    {
    QString GetRes = QString::fromUtf8(reply->readAll());
    qDebug() << "GetRes: " + GetRes;
    emit SendLog(GetRes);
    }

    Flow output:

    QThread *postThread = new QThread;
    MakePost *sendPost = new MakePost();
    sendPost->SetParam(Data, SubUrl, requestString);

    sendPost->moveToThread(postThread);
    sendPost->manager.moveToThread(postThread);
    connect(postThread, SIGNAL(started()), sendPost, SLOT(MakePostSignal()));
    postThread->start();

    and the interconnection of slots in mainwindow:

    connect(SendPost, SIGNAL(SendLog(QString)), this, SLOT(setLogs(QString)));

    without flow, everything works normally if I start the flow only results qDebug() << "GetRes: " + GetRes; And that's it. ♪ ♪

    Tell me tell me how to correctly set up a swelling signal between the flow, the main window?



  • You have a slot.

     void MainWindow::setLogs(QString param, QString text)  
    

    And in the line, you wrote.

    setLogs(QString)  
    

    It doesn't have to work in one flow. The number and type of parameters shall be the same as when the slot is declared in the signal and, accordingly, when calling. ♪ ♪ )




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2