hmmm! Dear wysota!
I not found signals and slots appropriate.
can you specify more for me?
Current, I have a function connect to URL:
{
QNetworkAccessManager manager;
QNetworkReply
*reply
=manager.
get(QNetworkRequest
(QUrl(str
)));
connect(reply,SIGNAL(readyRead()),&evLoop,SLOT(quit()));
connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),&evLoop,SLOT(quit()));
evLoop.exec();
qDebug()<<"kiemtraketnoi.cpp KTTruyenDuLieu Network Error"<<reply->error();
if(reply->error()==0)
{
strDuLieu
=QString::fromUtf8(reply
->readAll
());
}
else
{
qDebug()<<"kiemtraketnoi.cpp KTTruyenDuLieu Network Error"<<reply->error();
strDuLieu="";
QString msg
= reply
->errorString
() + " Retry?";
msgBox.setText(msg);
msgBox.exec();
{
KTTruyenDuLieu(str);
}
{
msgBox.close();
}
}
reply->deleteLater();
return strDuLieu;
}
QString KiemTraKetNoi::KTTruyenDuLieu(QString &str)
{
QNetworkAccessManager manager;
QNetworkReply *reply=manager.get(QNetworkRequest(QUrl(str)));
QEventLoop evLoop;
connect(reply,SIGNAL(readyRead()),&evLoop,SLOT(quit()));
connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),&evLoop,SLOT(quit()));
evLoop.exec();
QString strDuLieu="";
qDebug()<<"kiemtraketnoi.cpp KTTruyenDuLieu Network Error"<<reply->error();
if(reply->error()==0)
{
strDuLieu=QString::fromUtf8(reply->readAll());
}
else
{
qDebug()<<"kiemtraketnoi.cpp KTTruyenDuLieu Network Error"<<reply->error();
strDuLieu="";
QMessageBox msgBox;
QPushButton *okButton = msgBox.addButton(QString::fromUtf8("OK"), QMessageBox::ActionRole);
QPushButton *noButton = msgBox.addButton(QString::fromUtf8("No"),QMessageBox::RejectRole);
QString msg = reply->errorString() + " Retry?";
msgBox.setText(msg);
msgBox.exec();
if(msgBox.clickedButton()== (QAbstractButton*)okButton)
{
KTTruyenDuLieu(str);
}
else if(msgBox.clickedButton() == (QAbstractButton*)noButton)
{
msgBox.close();
}
}
reply->deleteLater();
return strDuLieu;
}
To copy to clipboard, switch view to plain text mode
I want to if time connect to website >5s, but application not connect to this web, application return messagebox "Not connect to webstie".
Bookmarks