Qt / QtConcurrent,Http在使用线程时永远不会完成

时间:2016-03-25 08:09:09

标签: multithreading qt qthread qnetworkaccessmanager qtconcurrent

我做了简单的HTTP get操作。我得到JSON结果,然后解析它。我在functuon中使用这个操作步骤。我用QtConcurrent :: run启动函数, HttpGet功能:

    void MobileOperations::GetHTTPData(MyGlobal::Metods MetodName, QString Parameters, QMap<QString, QVariant> paramlist)
{

parameter=new HttpRequest();
parameter->url=m_url;
parameter->metodname=MetodName;
parameter->resource=m_path;
parameter->appid=m_appid;
parameter->apppass=m_apppass;
parameter->parametersname=Parameters;
parameter->params=paramlist;
rest= new RestWebservice(parameter->GenerateHTTPQuery(),MetodName);
json=new JSonParser();
loop=new QEventLoop();

      QObject::connect(rest,SIGNAL(sendhttpdata(QByteArray,MyGlobal::Metods)),&json,SLOT(onGetData(QByteArray,MyGlobal::Metods)));
 QObject::connect(&json,SIGNAL(serilazitionCompleted()),loop,SLOT(quit()));


 rest->get();



  loop->exec();


}

在这里,Http获取请求启动,然后在循环中等待直到json结果被解析。我这样调用这个函数:

void MobileOperations::getUserAccountT( QString kullaniciAdi,  QString   sifre)
  {

 MyGlobal::Metods metod=MyGlobal::KullaniciGiris;
 QString parameters="{UserId}/{UserPass}/{GSM}";
 QMap<QString,QVariant> paramlist;
 paramlist["UserId"]=kullaniciAdi;
 paramlist["UserPass"]=sifre;
 paramlist["GSM"]="";

 GetHTTPData(metod,parameters,paramlist);

if(json.user.IsSuccess==true)
{
emit successlogin("Login Başarılı");
emit processstop("Login Başarılı");
}
else
{
    emit processstop("Bağlantı Başarısız Oldu");
}
 qDebug()<<json.user.IsSuccess<<json.user.UserName;

 }

  void MobileOperations::getUserAccount(QString kullaniciAdi, QString  sifre)
 {
 QFutureWatcher<void> watcher;
 connect(&watcher,SIGNAL(canceled()),&watcher,SLOT(deleteLater()));

QFuture<void> t1=       QtConcurrent::run(this,&getUserAccountT,kullaniciAdi,sifre);
watcher.setFuture(t1);
emit processstart("Bağlanıyor");



    }

我使用线程,因为避免冻结screan.But线程永远不会结束。我commet loop.exe(),线程完成但在这种情况下,我不能知道json值被填充,我错过了值。

0 个答案:

没有答案