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. QSqlQuery throwing a SIGABRT on .clear() or cleanup
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery throwing a SIGABRT on .clear() or cleanup

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 360 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.
  • X Offline
    X Offline
    Xenthan
    wrote on last edited by Xenthan
    #1

    My program is crashing when a QSqlQuery object is either being cleared or deleted, but only if the query is on an invalid entry. So if I call "while (query.next())" it will crash, but if I stop it at the second to last entry then it will delete just fine. It's returning valid values from the database, so I know the database is opening properly and that QSqlQuery is reading properly.

        int cycleCount = 0;
        int zoneid;
    
        QSqlQuery query(sql); //sql is a QSqlDatabase declared elsewhere 
        query.exec("SELECT MAX(zoneid) FROM zone_settings");
        query.next();
    
        int maxCount = query.value(0).toInt();
    
        zoneList = new zoneInfo[maxCount]; //Custom struct pointer declared elsewhere
        //query.clear() //Does not crash
        query.exec("SELECT zoneid FROM zone_settings");
    
        //while (query.next())
        //{
        //    cycleCount++;
        //    zoneid = query.value(0).toInt();
        //    zoneList[zoneid].id = zoneid;
    
        //}
        //query.clear(); //Crashes
    
       int returnedValues = query.size();
       for (int i = 0; i < returnedValues - 1; i++){
            query.next();
            cycleCount++;
            zoneid = query.value(0).toInt();
            zoneList[zoneid].id = zoneid;
        }
       query.clear(); //Does not crash
    
    JonBJ Christian EhrlicherC 2 Replies Last reply
    0
    • X Xenthan

      My program is crashing when a QSqlQuery object is either being cleared or deleted, but only if the query is on an invalid entry. So if I call "while (query.next())" it will crash, but if I stop it at the second to last entry then it will delete just fine. It's returning valid values from the database, so I know the database is opening properly and that QSqlQuery is reading properly.

          int cycleCount = 0;
          int zoneid;
      
          QSqlQuery query(sql); //sql is a QSqlDatabase declared elsewhere 
          query.exec("SELECT MAX(zoneid) FROM zone_settings");
          query.next();
      
          int maxCount = query.value(0).toInt();
      
          zoneList = new zoneInfo[maxCount]; //Custom struct pointer declared elsewhere
          //query.clear() //Does not crash
          query.exec("SELECT zoneid FROM zone_settings");
      
          //while (query.next())
          //{
          //    cycleCount++;
          //    zoneid = query.value(0).toInt();
          //    zoneList[zoneid].id = zoneid;
      
          //}
          //query.clear(); //Crashes
      
         int returnedValues = query.size();
         for (int i = 0; i < returnedValues - 1; i++){
              query.next();
              cycleCount++;
              zoneid = query.value(0).toInt();
              zoneList[zoneid].id = zoneid;
          }
         query.clear(); //Does not crash
      
      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #3

      @Xenthan said in QSqlQuery throwing a SIGABRT on .clear() or cleanup:

      zoneList[zoneid].id

      Check for zoneid out of bounds or better use an appropriate container instead c magic.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • X Xenthan

        My program is crashing when a QSqlQuery object is either being cleared or deleted, but only if the query is on an invalid entry. So if I call "while (query.next())" it will crash, but if I stop it at the second to last entry then it will delete just fine. It's returning valid values from the database, so I know the database is opening properly and that QSqlQuery is reading properly.

            int cycleCount = 0;
            int zoneid;
        
            QSqlQuery query(sql); //sql is a QSqlDatabase declared elsewhere 
            query.exec("SELECT MAX(zoneid) FROM zone_settings");
            query.next();
        
            int maxCount = query.value(0).toInt();
        
            zoneList = new zoneInfo[maxCount]; //Custom struct pointer declared elsewhere
            //query.clear() //Does not crash
            query.exec("SELECT zoneid FROM zone_settings");
        
            //while (query.next())
            //{
            //    cycleCount++;
            //    zoneid = query.value(0).toInt();
            //    zoneList[zoneid].id = zoneid;
        
            //}
            //query.clear(); //Crashes
        
           int returnedValues = query.size();
           for (int i = 0; i < returnedValues - 1; i++){
                query.next();
                cycleCount++;
                zoneid = query.value(0).toInt();
                zoneList[zoneid].id = zoneid;
            }
           query.clear(); //Does not crash
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @Xenthan
        https://doc.qt.io/qt-6/qsqlquery.html#clear hardly encourages you to use it! You use the same QSqlQuery query instance for two distinct exec() statements. If you use two separate instances do you have any crash?

        X 1 Reply Last reply
        0
        • X Xenthan

          My program is crashing when a QSqlQuery object is either being cleared or deleted, but only if the query is on an invalid entry. So if I call "while (query.next())" it will crash, but if I stop it at the second to last entry then it will delete just fine. It's returning valid values from the database, so I know the database is opening properly and that QSqlQuery is reading properly.

              int cycleCount = 0;
              int zoneid;
          
              QSqlQuery query(sql); //sql is a QSqlDatabase declared elsewhere 
              query.exec("SELECT MAX(zoneid) FROM zone_settings");
              query.next();
          
              int maxCount = query.value(0).toInt();
          
              zoneList = new zoneInfo[maxCount]; //Custom struct pointer declared elsewhere
              //query.clear() //Does not crash
              query.exec("SELECT zoneid FROM zone_settings");
          
              //while (query.next())
              //{
              //    cycleCount++;
              //    zoneid = query.value(0).toInt();
              //    zoneList[zoneid].id = zoneid;
          
              //}
              //query.clear(); //Crashes
          
             int returnedValues = query.size();
             for (int i = 0; i < returnedValues - 1; i++){
                  query.next();
                  cycleCount++;
                  zoneid = query.value(0).toInt();
                  zoneList[zoneid].id = zoneid;
              }
             query.clear(); //Does not crash
          
          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #3

          @Xenthan said in QSqlQuery throwing a SIGABRT on .clear() or cleanup:

          zoneList[zoneid].id

          Check for zoneid out of bounds or better use an appropriate container instead c magic.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • JonBJ JonB

            @Xenthan
            https://doc.qt.io/qt-6/qsqlquery.html#clear hardly encourages you to use it! You use the same QSqlQuery query instance for two distinct exec() statements. If you use two separate instances do you have any crash?

            X Offline
            X Offline
            Xenthan
            wrote on last edited by
            #4

            @Christian-Ehrlicher

            This was it, at some point the database data became zero referenced so I was 1 element short on the array.

            1 Reply Last reply
            0
            • X Xenthan has marked this topic as solved on
            • X Xenthan has marked this topic as unsolved on
            • X Xenthan has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved