Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Getting data from a lot of QMaps into one QMap.



  • 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,



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



  • 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());
    }
    @



  • 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?



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



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


Log in to reply