I make simple HTTP get operation.I get JSON result , then parse it. I use this operations steps in functuon.I start function with QtConcurrent::run , HttpGet Function :
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();
}
in here, Http get request start, then wait in loop until json result is parsed.I call this function like this:
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");
}
I use thread because of avoiding freeze screan.But thread never ends.I commet loop.exe() , thread finish but in this case I can't know json value is filled , I miss value.