I am building a app that contacts the server for data, gets it and then does some processing before displaying the result.

I have created a mapping function that maps all the functions that need to be called if a particular request has to be successful.

This code is the main part where all the calling is done.

Qt Code:
  1. if (check_if_clientID_is_present())
  2. call = "teci.create.client";
  3. qDebug() << "call"<< call;
  4.  
  5. if(!call.isEmpty() && API_Request_Pointer == false)
  6. mapping(call);
To copy to clipboard, switch view to plain text mode 

This is the mapping code where the required functions are called.
First i prepare the xml document, call the fetch function, then wait for the readyread and requestfinished signals, then call the parsing function and then exit the mapping function

Qt Code:
  1. void MainWindow::mapping(QString callname)
  2. {
  3. qDebug() <<"in mapping";
  4. QThread thread;
  5. if(call.compare("teci.create.client",callname)== 0)
  6. {
  7. qDebug() <<"inside create client";
  8. API_Request_Pointer = true;
  9. create_client();
  10. fetch();
  11. connect(&http, SIGNAL(readyRead(const QHttpResponseHeader &)),
  12. this, SLOT(readData(const QHttpResponseHeader &)));
  13.  
  14. connect(&http, SIGNAL(requestFinished(int, bool)),
  15. this, SLOT(finished(int, bool)));
  16. parse_create_client();
  17. API_Request_Pointer = false;
  18. qDebug() <<"leaving create client";
  19. }
  20. else if (call.compare("teci.test.reverse",callname)== 0)
  21. {
  22. API_Request_Pointer = true;
  23. reverse_string();
  24. fetch();
  25. connect(&http, SIGNAL(readyRead(const QHttpResponseHeader &)),
  26. this, SLOT(readData(const QHttpResponseHeader &)));
  27.  
  28. connect(&http, SIGNAL(requestFinished(int, bool)),
  29. this, SLOT(finished(int, bool)));
  30. parse_reverse_string();
  31. API_Request_Pointer = false;
  32. }
  33. qDebug() <<"leaving mapping";
  34.  
  35. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void MainWindow::fetch()
  2. {
  3.  
  4. xml.clear();
  5.  
  6. QByteArray string ("username");
  7. string.append(":");
  8. string.append("12345");
  9. QString encoded = string.toBase64();
  10. qDebug() <<"String"<< string <<"Encoded" <<encoded ;
  11.  
  12. QUrl url("http://..../");
  13. url.setUserName("username");
  14. url.setPassword("12345");
  15.  
  16. QHttpRequestHeader header("POST","/api/");
  17. header.setValue("Host",url.host());
  18. header.setValue("Path",url.path());
  19. header.setValue("Authorization","Basic " + encoded);
  20.  
  21. http.setHost(url.host(),url.port(80));
  22.  
  23. connectionId = http.request(header,xmlrequest);
  24. qDebug() << "Leaving fetch";
  25. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void MainWindow::create_client()
  2. {
  3. here i add tags and create the xml
  4.  
  5. xmlrequest.append(doc.toString());
  6. qDebug() << xmlrequest.data();
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void MainWindow::readData(const QHttpResponseHeader &resp)
  2. {
  3.  
  4.  
  5. if (resp.statusCode() != 200)
  6. http.abort();
  7. else
  8. {
  9. xml.addData(http.readAll());
  10. }
  11. qDebug() << "Leaving readdata";
  12. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void MainWindow::finished(int id, bool error)
  2. {
  3. qDebug() <<"Error" <<http.errorString();
  4. if (error)
  5. qWarning("Received error during HTTP fetch.");
  6.  
  7. qDebug() << "Leaving finished";
  8. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void MainWindow::parse_create_client()
  2. {
  3. qDebug() <<"Entering parser";
  4. while (!xml.atEnd())
  5. {
  6. xml.readNext();
  7. qDebug()<<xml.readNext();
  8. if (xml.isStartElement())
  9. {
  10. currentTag = xml.name().toString();
  11.  
  12. if (currentTag == "client")
  13. API_key += xml.attributes().value("key").toString();
  14. qDebug() << "CurrentTag"<<currentTag;
  15.  
  16. }
  17.  
  18. else if (xml.isCharacters() && !xml.isWhitespace())
  19. {
  20.  
  21. if (currentTag == "password")
  22. API_password += xml.text().toString();
  23. }
  24. }
  25.  
  26. qDebug() << "webiste_clientID"<< API_key;
  27. qDebug() << "webiste_serial no"<<API_password;
  28.  
  29. }
  30. }
To copy to clipboard, switch view to plain text mode 

After reading the data, i write it down in a file.

This is the output i am getting.

Qt Code:
  1. Getting data from the webiste
  2. call "teci.create.client"
  3. in mapping
  4. inside create client
  5. <request version="0.1" >
  6. <call name="teci.client.create" >
  7. <client>
  8. <kind>MOBILE</kind>
  9. <name>API Test suite 7001</name>
  10. </client>
  11. </call>
  12. </request>
  13.  
  14. Leaving fetch
  15. Entering parser
  16. 1
  17. webiste_clientID ""
  18. webiste_serial no ""
  19. leaving create client
  20. leaving mapping
  21. Leaving finished
  22. Leaving readdata
To copy to clipboard, switch view to plain text mode 

the readyread and requestfinished signals are being called after the parsing function has been called.

How can i wait for the signal and then call the parsing function??