There is a slot in the main class mainwindow class, which outputs data to QTextBrowser :
void MainWindow::setLogs(QString param, QString text) { qDebug()<<text; ui->Logs->append(text); } There is a class that runs in a separate thread, makes a POST request and should insert the data into 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); } Call flow:
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 a bunch of slot-stream in mainwindow:
connect(SendPost, SIGNAL(SendLog(QString)), this, SLOT(setLogs(QString))); Without a thread, everything works fine, but if I run in a stream, only the result is qDebug() << "GetRes: " + GetRes; and all ...
Tell me how to create a signal-slot design between the stream - the main window?