Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]How retrive Data from QList< QPair<QString, QString> > tokens = getTokenUrl.queryItems(); and Copy to QString
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 11.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yravi
    wrote on last edited by
    #1

    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

    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->writeHead(200);
         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;");
         resp->write("&lt;/form&gt;");
         resp->write("&lt;/body&gt;&lt;/html>");
         resp->end();@
    

    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"

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yravi
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Try this.

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

          list.append(qMakePair(QString("PthinkS"),QString("Bengaluru")));
          list.append(qMakePair(QString("PthinkS"),QString("India")));
          list.append(qMakePair(QString("Dheeru"),QString("Bengaluru")));
          
          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
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yravi
            wrote on last edited by
            #5

            @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);
                      if(i==0)
                      {
                          qDebug() << "i=0 came";
                           user =pair.first;
                           userdata =pair.second;
                      }
            
                      if(i==1)
                      {
                          qDebug() << "i=1 came";
                           password =pair.first;
                           passworddata =pair.second;
                      }
            
                      if(i==2)
                      {
                          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;@@@
            
            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

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

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                yravi
                wrote on last edited by
                #7

                Fine..Thank you

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved