Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QMap iteration crash

    General and Desktop
    3
    6
    1823
    Loading More Posts
    • 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
      nullstellensatz last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        @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 Reply Quote 0
        • N
          nullstellensatz last edited by

          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 Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

            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 Reply Quote 1
            • N
              nullstellensatz last edited by

              @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 Reply Quote 0
              • Chris Kawa
                Chris Kawa Moderators last edited by Chris Kawa

                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 Reply Quote 0
                • First post
                  Last post