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. Getting data from a lot of QMaps into one QMap.
Forum Updated to NodeBB v4.3 + New Features

Getting data from a lot of QMaps into one QMap.

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 6.7k 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.
  • P Offline
    P Offline
    piotrekd
    wrote on last edited by
    #1

    Hello everyone,

    recently I got an strange (for me) error by my project. Idea is: from a couple of QMaps I need to retrieve data and put into one QMap.

    I wrote this piece of code: (getKeywords() returns a QMap<QString, unsigned>)
    @
    QMap<QString, unsigned> total_of_first;

    for(int i = 0; i < this->first->getLogsNumber(); i++)
    {
        for(QMap<QString, unsigned>::iterator   j = this->first->getPool().at(i)->getKeywords().begin();
                                                j != this->first->getPool().at(i)->getKeywords().end(); j++)
        {
            if(total_of_first.contains(j.key()))
            {
                total_of_first[ j.key() ] += j.value();
            }
            else
            {
                total_of_first.insert(j.key(), j.value()); // I found out that problem is here, but actually I don't know why
            }
        }
    }
    

    @

    Could anyone give me a tip how to resolve this problem? I'll be very glad for all hints.
    Best regards,

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      You may want to share your error message. That would help understanding your problem.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        piotrekd
        wrote on last edited by
        #3

        Ooops, sorry:P I forgot about it.

        There is no message. There is "Program has unexpectly finished" if i put this line which is in "else":
        @
        else
        {
        total_of_first.insert(j.key(), j.value());
        }
        @

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          I do not use QMap. I am more used to stl's map. In general your code is quite complicated, but seems to be correct.

          I am wondering how often it loops?
          Could it be that the map you are accessing is empty?

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • P Offline
            P Offline
            piotrekd
            wrote on last edited by
            #5

            Actually, there shouldn't be way that map could be empty. But I'll check it out;)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Why don't you try your debugger, and see where your application crashes exactly?

              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