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.



  • As far as I know the http->post() is non-blocking call. So, operation still in progress. Try to connect to your "http" object signals and you will be notified about state change.



  • Hi,

    in any case, I suggest you to use QNetworkAccessManager. QHttp has been deprecated.

    T.



  • Thank blex and Antonio very much, I try to connect with done() and it's connect.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.