Change QHttp:: state() from unconnected to connected
I try to write program which handle web service using QHttp :: Post().
When i click on button ,it will sent post request.
but the QHttp :: state() =Unconnected.
Code :
void MainWindow::LogIn()
{
ui->btnLogin->setEnabled(false);
QUrl url;
url.setPath("path of API");
QByteArray data("username=");
data.append(ui->txtUserName->text());
data.append("&password=");
data.append(ui->txtPassword->text());
http->setHost("Website.com");
int result= http->post(url.toString(),data);//note result =2
http->state();//note state = Unconnected
}
how can change state of http to connect ???
Thank you for your help.
Re: Change QHttp:: state() from unconnected to connected
QHttp works in asynchronous way. You have to wait before the connection is actually made as setHost() only schedules the connection. Similarily post() only queues the actual POST request that will be made after QHttp manages to connect to the host.