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. Why does one conversion fail but not the other?

Why does one conversion fail but not the other?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.3k 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.
  • M Offline
    M Offline
    MScottM
    wrote on last edited by
    #1

    Here is a sample of my logfile (with header):

    Date,Time(UTC),Bus Name,PGN#,PGN Priority,PGN Src. Addr.,PGN Dest. Addr.,Data Length,DB0,DB1,DB2,DB3,DB4,DB5,DB6,DB7
    20151029,140003,NMEA2000,127250,2,01,ff,8,ff,f1,bc,ff,7f,ff,7f,fd
    20151029,140040,NMEA2000,129025,2,03,ff,8,ab,23,8e,13,0e,8f,6b,b9

    I've built QStringLists with the data that I need (DB0, DB1...)

    And I'm trying to make it human readable. Here is my code to get at the GPS position in the log data:

    void MainWindow::on_btnPosition_clicked()
    {
    
        //BUILD LATITUDE HEX NUMBER FROM LOG DATA
        PGNListCount = PGNList.count();
        for (int i=0;i<PGNListCount;++i) {
            if (PGNList.at(i).contains("129025")) {
                DB30Data << DB3.at(i) + DB2.at(i) + DB1.at(i) + DB0.at(i);
                }
         }    
        qDebug() << "DB30data" << DB30Data.at(10);
    
        //BUILD LONGITUDE HEX NUMBER FROM LOG DATA
        PGNListCount = PGNList.count();
        qDebug() << "PGNListCount" << PGNListCount;
        for (int i=0;i<PGNListCount;++i) {
            if (PGNList.at(i).contains("129025")) {
                DB74Data << DB7.at(i) + DB6.at(i) + DB5.at(i) + DB4.at(i);
    
                }
         }
        qDebug() << "DB74Data" << DB74Data.at(10);
    
    
    
        //CONVERT LATITUDE HEX TO FLOAT
        int DB30DataCount = DB30Data.count();
        for (int i=0; i<DB30DataCount;++i) {
                latitudeFromHex = ((DB30Data.at(i).toInt(&ok, 16))*0.0000001);
                if (!ok){
                    qDebug() << "latitude conversion failed";
                    break;
                }
                Latitude.append(latitudeFromHex);
        }
        qDebug() << "Latitude" << QString::number(Latitude.at(10),'f',7);
    
    
        //CONVERT LONGITUDE HEX TO FLOAT
        int DB74DataCount = DB74Data.count();
        qDebug() << "DB74DataCount" << DB74DataCount;
        for (int i=0; i<DB74DataCount; ++i) {
                longitudeFromHex = ((DB74Data.at(i).toInt(&ok, 16))*0.0000001);
                if (!ok){
                    qDebug() << "longitude conversion failed";
                    break;
                }
                Longitude.append(longitudeFromHex);
        }
        qDebug() << "Longitude" << QString::number(Longitude.at(10),'f',10);
    
    }
    

    And here are the resulting debug statements:

    Debugging starts
    DB30data "138e23ab"
    PGNListCount 1000
    DB74Data "b96b8f1d"
    Latitude "32.8082347"
    DB74DataCount 200
    longitude conversion failed
    ASSERT failure in QVector<T>::at: "index out of range", file C:\Qt\5.5\mingw492_32\include/QtCore/qvector.h, line 393
    Debugging has finished

    Latitude and Longitude are declared as QVector<long double>
    latitudeFromHex and longitudeFromHex are declared as long double

    Why is the Latitude conversion working, but the Longitude conversion failing? This is a case where I need a nudge in the right direction - I haven't turned up anything in my own research.

    Thanks for any help!

    kshegunovK 1 Reply Last reply
    0
    • M MScottM

      Here is a sample of my logfile (with header):

      Date,Time(UTC),Bus Name,PGN#,PGN Priority,PGN Src. Addr.,PGN Dest. Addr.,Data Length,DB0,DB1,DB2,DB3,DB4,DB5,DB6,DB7
      20151029,140003,NMEA2000,127250,2,01,ff,8,ff,f1,bc,ff,7f,ff,7f,fd
      20151029,140040,NMEA2000,129025,2,03,ff,8,ab,23,8e,13,0e,8f,6b,b9

      I've built QStringLists with the data that I need (DB0, DB1...)

      And I'm trying to make it human readable. Here is my code to get at the GPS position in the log data:

      void MainWindow::on_btnPosition_clicked()
      {
      
          //BUILD LATITUDE HEX NUMBER FROM LOG DATA
          PGNListCount = PGNList.count();
          for (int i=0;i<PGNListCount;++i) {
              if (PGNList.at(i).contains("129025")) {
                  DB30Data << DB3.at(i) + DB2.at(i) + DB1.at(i) + DB0.at(i);
                  }
           }    
          qDebug() << "DB30data" << DB30Data.at(10);
      
          //BUILD LONGITUDE HEX NUMBER FROM LOG DATA
          PGNListCount = PGNList.count();
          qDebug() << "PGNListCount" << PGNListCount;
          for (int i=0;i<PGNListCount;++i) {
              if (PGNList.at(i).contains("129025")) {
                  DB74Data << DB7.at(i) + DB6.at(i) + DB5.at(i) + DB4.at(i);
      
                  }
           }
          qDebug() << "DB74Data" << DB74Data.at(10);
      
      
      
          //CONVERT LATITUDE HEX TO FLOAT
          int DB30DataCount = DB30Data.count();
          for (int i=0; i<DB30DataCount;++i) {
                  latitudeFromHex = ((DB30Data.at(i).toInt(&ok, 16))*0.0000001);
                  if (!ok){
                      qDebug() << "latitude conversion failed";
                      break;
                  }
                  Latitude.append(latitudeFromHex);
          }
          qDebug() << "Latitude" << QString::number(Latitude.at(10),'f',7);
      
      
          //CONVERT LONGITUDE HEX TO FLOAT
          int DB74DataCount = DB74Data.count();
          qDebug() << "DB74DataCount" << DB74DataCount;
          for (int i=0; i<DB74DataCount; ++i) {
                  longitudeFromHex = ((DB74Data.at(i).toInt(&ok, 16))*0.0000001);
                  if (!ok){
                      qDebug() << "longitude conversion failed";
                      break;
                  }
                  Longitude.append(longitudeFromHex);
          }
          qDebug() << "Longitude" << QString::number(Longitude.at(10),'f',10);
      
      }
      

      And here are the resulting debug statements:

      Debugging starts
      DB30data "138e23ab"
      PGNListCount 1000
      DB74Data "b96b8f1d"
      Latitude "32.8082347"
      DB74DataCount 200
      longitude conversion failed
      ASSERT failure in QVector<T>::at: "index out of range", file C:\Qt\5.5\mingw492_32\include/QtCore/qvector.h, line 393
      Debugging has finished

      Latitude and Longitude are declared as QVector<long double>
      latitudeFromHex and longitudeFromHex are declared as long double

      Why is the Latitude conversion working, but the Longitude conversion failing? This is a case where I need a nudge in the right direction - I haven't turned up anything in my own research.

      Thanks for any help!

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Have a look at the stack trace, it will point you to the exact line in your code where you overrun the vector.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        MScottM
        wrote on last edited by
        #3

        I tried setting a breakpoint and stepping through while watching the stack, but it doesn't crash anywhere - it just drops to the boolean check and breaks out. If I take the check out, it just loads the array with zeros.

        E 1 Reply Last reply
        0
        • M MScottM

          I tried setting a breakpoint and stepping through while watching the stack, but it doesn't crash anywhere - it just drops to the boolean check and breaks out. If I take the check out, it just loads the array with zeros.

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

          @MScottM You have

              if (!ok){
                          qDebug() << "longitude conversion failed";
                          break;
                      }
                      Longitude.append(longitudeFromHex);
              }
              qDebug() << "Longitude" << QString::number(Longitude.at(10),'f',10);
          

          What does it show if you change to

          qDebug() << "longitude conversion failed at " << i;
          

          and

          qDebug() << "Longitude count " << Longitude.count();
          qDebug() << "Longitude" << QString::number(Longitude.at(10),'f',10);
          
          1 Reply Last reply
          0
          • M Offline
            M Offline
            MScottM
            wrote on last edited by
            #5

            @Eeli-K Thanks for the idea!

            Debug statements:

            DB30data "138e23ab"
            PGNListCount 1000
            DB74Data "b96b8f0e"
            Latitude "32.8082347"
            DB74DataCount 200
            longitude conversion failed at 0
            longitude count 0
            ASSERT failure in QVector<T>::at: "index out of range", file C:\Qt\5.5\mingw492_32\include/QtCore/qvector.h, line 393
            Debugging has finished

            I put all three debug statements in the 'if' check like this:

            if (!ok){
                            qDebug() << "longitude conversion failed at " << i;
                            qDebug() << "longitude count" << Longitude.count();
                            qDebug() << "Longitude" << QString::number(Longitude.at(i),'f',10);
                            break;
                        }
            
            E 1 Reply Last reply
            0
            • M MScottM

              @Eeli-K Thanks for the idea!

              Debug statements:

              DB30data "138e23ab"
              PGNListCount 1000
              DB74Data "b96b8f0e"
              Latitude "32.8082347"
              DB74DataCount 200
              longitude conversion failed at 0
              longitude count 0
              ASSERT failure in QVector<T>::at: "index out of range", file C:\Qt\5.5\mingw492_32\include/QtCore/qvector.h, line 393
              Debugging has finished

              I put all three debug statements in the 'if' check like this:

              if (!ok){
                              qDebug() << "longitude conversion failed at " << i;
                              qDebug() << "longitude count" << Longitude.count();
                              qDebug() << "Longitude" << QString::number(Longitude.at(i),'f',10);
                              break;
                          }
              
              E Offline
              E Offline
              Eeli K
              wrote on last edited by
              #6

              @MScottM It's obvious that

              longitudeFromHex = ((DB74Data.at(i).toInt(&ok, 16))*0.0000001);
              

              doesn't work as you expect. Break it down to pieces, one new function call/assignment per line, and follow it with debugger or add a qDebug line after each line.

              1 Reply Last reply
              1
              • M Offline
                M Offline
                MScottM
                wrote on last edited by
                #7

                Got it! I had to convert to LongLong:

                longitudeFromHex = ((DB74Data.at(i).toLongLong(&ok, 16))*0.0000001);

                did the trick.

                Thanks for taking the time to post!

                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