QString My_class::My_Method()
{
QNetworkAccessManager *manager= new QNetworkAccessManager(this);
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(ReplayFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl(My_URL)));
return str;
}
void My_class::ReplayFinished(QNetworkReply *replay)
{
QString buffer;
if(replay->isOpen())
{
buffer=replay->readAll();
//treatment on the buffer and the public Qstring 'str'(declared in My_class.h) is updated
}
}
嗨,问题是在 main 中调用 My_method() 时,QString str
它是空的,因为它是以这种方式返回的,而无需等待 ReplayFinished 更新它。等待工作完成的解决方案可能是什么,以便我可以获得正确的信息,而不是跳过它并返回其他内容。谢谢你。