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. QMap iteration crash

QMap iteration crash

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

    I am using Qt 5.5 on Windows 8.1. When I run the code below, the application is able to get through one iteration, but crashes on the second one. 100% reproducible. (Copy/paste it into a Qt Creator instance and test; it might work for you).

    #include <QCoreApplication>
    #include <QDebug>
    #include <utility>
    
    using std::pair;
    
    int main(int argc, char *argv[]) {
        QCoreApplication a(argc, argv);
        QMap<QString, pair<QString, QString> > table_def = {
            {"alpha", {"INTEGER", "PRIMARY KEY"}},
            {"beta", {"VARCHAR", ""}},
            {"gamma", {"VARCHAR", ""}},
            {"delta", {"REAL", "DEFAULT 0"}},
            {"epsilon", {"INTEGER", ""}},
            {"zeta", {"INTEGER", ""}},
            {"eta", {"INTEGER", ""}},
            {"theta", {"INTEGER", ""}},
            {"iota", {"VARCHAR", ""}},
            {"kappa", {"INTEGER", "DEFAULT 0"}},
            {"lambda", {"INTEGER", "DEFAULT 0"}}
        };
    
        QMapIterator<QString, pair<QString, QString> > it(table_def);
        while (it.hasNext()) {
          it.next();
          const QString& col_name = it.key();
          qDebug() << col_name;
          const QString& col_type = it.value().first;
          qDebug() << col_type;
          const QString& extra_def = it.value().second;
          qDebug() << extra_def;
        }
        return a.exec();
    }
    

    My Visual Studio debugger says: Unhandled exception at 0x000000006904E394 (Qt5Cored.dll) in helloqt.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

    If it is of any relevance, I added DEFINES += Q_COMPILER_INITIALIZER_LISTS in my project file to enable initialization of QContainers with initializer lists. Also, if I replace the STL pair with QPair, the application crashes at the first iteration.

    I don't see anything wrong with this code. What could be happening?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @nullstellensatz said:

      qt 5.4.1 on win 7.
      No crash with your code.
      also added DEFINES += Q_COMPILER_INITIALIZER_LISTS

      for test, if you change all "" (empty) to something , does it still crash ?
      Just a thought since you say it crash on second. (first "")

      Code looks perfectly valid to me.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nullstellensatz
        wrote on last edited by
        #3

        The first entry to be printed is actually "theta" (since the entries are not ordered by key), which has an empty string as the second value.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Which version and update of VS are you using?
          Initializer lists were infested with subtle but horrid bugs prior to VS2013 Update 3 and are not entirely standards conforming even in Update 4, although the above seems to compile and run fine with Qt5.5 in VS2013 Update 4 (the extra define seems not needed anymore?).

          1 Reply Last reply
          1
          • N Offline
            N Offline
            nullstellensatz
            wrote on last edited by
            #5

            @Chris-Kawa The last time I updated Visual Studio was sometime in 2014. After getting the most recent version of Visual Studio this probelm went away.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by Chris Kawa
              #6

              Great.

              Btw. you can check which update you're running by going to Help->About Microsoft Visual Studio.
              For example the latest update reads
              Microsoft Visual Studio 2013
              Version 12.0.31101.00 Update 4

              Btw 2. On monday (20.07.2015) VS 2015 comes out, which has greatly improved c++11 standard support.

              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