[SOLVED]How retrive Data from QList< QPair<QString, QString> > tokens = getTokenUrl.queryItems(); and Copy to QString

  • Hi ALL,

    i have written a webserver program in Qt using Qhttp, where in a form the user will enter the data in textboxes and submit it, as per the below program i am receiving each text box data in "QList< QPair<QString, QString> > tokens" term, and on using QMultimap (suggested by another forum thread) used it, but i can only access the one text box data only. Now i requite the entire data to be copied to QString of the specific as shown in below Code

    @ QUrl getTokenUrl(req->url());

        QList< QPair<QString, QString> > tokens = getTokenUrl.queryItems();
          qDebug() << "tokens size"<< tokens.size();
          qDebug() <<"tokens data"<< tokens;
          QMultiMap<QString, QString> queryParams1;
          QPair<QString, QString> tokenPair1;
          foreach (tokenPair1, tokens) {
              queryParams1.insert(tokenPair1.first.trimmed(), tokenPair1.second.trimmed());
          qDebug() <<"data2"<<queryParams1;
          QString user =tokenPair1.first;
          QString userdata =tokenPair1.second;

    // QString password =tokenPair2.first;
    // QString passworddata =tokenPair2.second;

           qDebug() <<"user"<< user;
           qDebug() <<"userdata"<< userdata;

    // qDebug() <<"password"<< password;
    // qDebug() <<"passworddata"<< passworddata;

         resp->setHeader("Content-Type", "text/html; charset=ISO-8859-1");
         resp->write("&lt;html&gt;&lt;head>&lt;title&gt;Greeting App&lt;/title&gt;&lt;/head>&lt;body&gt;");
         resp->write("&lt;form name=\"input\" action=\"\" method=\"GET\"&gt;");
         resp->write("Username: &lt;input type=\"text\" name=\"user\"&gt;&lt;br>");
         resp->write("Password: &lt;input type=\"text\" name=\"password\"&gt;&lt;br>");
          resp->write("date: &lt;input type=\"text\" name=\"date\"&gt;&lt;br><br>");
         resp->write("&lt;input type=\"submit\" value=\"submit\"&gt;");

    Current Result:*

    tokens size 3
    tokens data (QPair("user","1") , QPair("password","2") , QPair("date","3") )
    data2 QMap(("date", "3")("password", "2")("user", "1"))
    user "date"
    userdata "3"

  • Not quite clear on what output you require. Let me try answering. It is a QList with QPair. I feel you can iterate over the QList and get each QPair Item. From each Pair Item you construct whatever the QString you require.

  • Hi Dheerendra

    can u please provide sample code how to iterate through QList and get each Qpair item. and save it in another QString or QByteArray.

    My requirement is i am getting the text box data from the form on submit button is clicked through html code into QList< Qpair <QString,QString> >, and i can watch it on terminal, now i want to analyze the data and transmit over the serial port. For that purpose i have to store the data in a another QString. Pls Guid for this

  • Try this.

    @ QList<QPair<QString, QString> > list;

    qDebug() << "List Count "<<list.count();
    for (int i=0;i<list.count();i++){
        QPair<QString, QString> pair = list.at(i);
        qDebug() << pair.first << " " << pair.second;

  • @dheerendra

    Thank you got the values into the QString as per the below code, can u please suggest is it the right way of implementation, pls provide your email id or telephone number for communication i am very much interested in learning Qt--
    @QString user;
    QString userdata;
    QString password;
    QString passworddata;
    QString date;
    QString datedata;

    QList<QPair<QString, QString> > list= getTokenUrl.queryItems();;

          qDebug() << "List Count "<<list.count();
          for (int i=0;i<list.count();i++){
              QPair<QString, QString> pair = list.at(i);
                  qDebug() << "i=0 came";
                   user =pair.first;
                   userdata =pair.second;
                  qDebug() << "i=1 came";
                   password =pair.first;
                   passworddata =pair.second;
                  qDebug() << "i=2 came";
                   date =pair.first;
                   datedata =pair.second;
              qDebug() << pair.first << " " << pair.second;
           qDebug() <<"user"<< user;
           qDebug() <<"userdata"<< userdata;
           qDebug() <<"password"<< password;
           qDebug() <<"passworddata"<< passworddata;
           qDebug() << "Date"<< date;
           qDebug() << "DateDate"<<datedata;@@@

  • Please look at our web-site. You can drop in-mail from this profile.

  • Fine..Thank you

Log in to reply

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