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 to traverse QMap as this QMap< QString, QMap< QString,QStringList > >?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]how to traverse QMap as this QMap< QString, QMap< QString,QStringList > >?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.2k 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.
  • F Offline
    F Offline
    freebigfish
    wrote on last edited by
    #1

    Hi,all.I'm faced a problem that traverse an QMap like this QMap< QString, QMap< QString,QStringList > >,but I failed.Can someone give me an advice?

    1 Reply Last reply
    0
    • IamSumitI Offline
      IamSumitI Offline
      IamSumit
      wrote on last edited by
      #2

      Hi.
      and welcome to Qt devnet.

      You can do it in either way.
      Qt provides two ways : Java-style iterator and STL-style iterator

      1 .Java-style iterator

      @
      QMap< QString, QMap< QString,QStringList > > map1;
      QMap< QString,QStringList > map2,temp;

      QMapIterator<QString, QMap< QString,QStringList > > i1(map1);
      while (i1.hasNext())
      {
      i1.next();
      qDebug() <<"@"<< i1.key() << ": " << i1.value() << endl;

      temp = i1.value();

      QMapIterator<QString, QStringList> i2(temp);
      while (i2.hasNext())
      {
      i2.next();
      qDebug()<<"@@" <<i2.key() << ": " << i2.value() << endl;
      QStringList strListTemp=i2.value();
      foreach(QString str,strListTemp)
      {
      qDebug()<<"list :"<<str;
      }
      }

      }

      @

      2.STL-style iterator

      @
      QMap< QString, QMap< QString,QStringList > >::const_iterator i1 = map1.constBegin();
      while (i1 != map1.constEnd())
      {
      qDebug() << i1.key() << ": " << i1.value() << endl;
      temp = i1.value();

      QMap< QString,QStringList > ::const_iterator i2 = temp.constBegin();

      while (i2 != temp.constEnd())
      {
      qDebug() << i2.key() << ": " << i2.value() << endl;
      QStringList strListTemp=i2.value();
      foreach(QString str,strListTemp)
      {
      qDebug()<<"list :"<<str;
      }
      ++i2;

      }
      ++i1;

      }
      @

      Hope this helps.

      Be Cute

      1 Reply Last reply
      0
      • F Offline
        F Offline
        freebigfish
        wrote on last edited by
        #3

        Thanks a lots! And how can i insert an item to the QStringList in the map?

        1 Reply Last reply
        0
        • IamSumitI Offline
          IamSumitI Offline
          IamSumit
          wrote on last edited by
          #4

          Hi.
          it is not a tough ask.
          you should do it your owns.
          The logic should be yours.i just can guide you ;not to do your job.

          BTW. There is a lot of insertion functions/mechanism.Have a look on Qt Docs and examples.

          Be Cute

          1 Reply Last reply
          0
          • F Offline
            F Offline
            freebigfish
            wrote on last edited by
            #5

            Thanks again for reply.i'm a newbiee and faced this problem for long time. with your help,i resolved this problem finally.before that,i used your code with error.

            1 Reply Last reply
            0
            • IamSumitI Offline
              IamSumitI Offline
              IamSumit
              wrote on last edited by
              #6

              That's nice.
              Now Please add thread title as [SOLVED] so other members can notify that soultion has been found.

              Be Cute

              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