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. ASSERT failure in QList<T>::operator[]: "index out of range"
Forum Updated to NodeBB v4.3 + New Features

ASSERT failure in QList<T>::operator[]: "index out of range"

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 5 Posters 10.5k Views 2 Watching
  • 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.
  • JerwinprabuJ Offline
    JerwinprabuJ Offline
    Jerwinprabu
    wrote on last edited by Jerwinprabu
    #7

    @joeQ When I was try to run the program I got the error

    error: return-statement with a value, in function returning 'void' [-fpermissive]
             return false;
    
    joeQJ jsulmJ 2 Replies Last reply
    0
    • JerwinprabuJ Jerwinprabu

      @joeQ When I was try to run the program I got the error

      error: return-statement with a value, in function returning 'void' [-fpermissive]
               return false;
      
      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by joeQ
      #8

      @Jerwinprabu (⊙o⊙)…

      bool myFunctionName() ///< Notes; function return value type must bool
      {
            /* ... */
            return true;
      }
      

      Just do it!

      1 Reply Last reply
      4
      • JerwinprabuJ Jerwinprabu

        @joeQ When I was try to run the program I got the error

        error: return-statement with a value, in function returning 'void' [-fpermissive]
                 return false;
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #9

        @Jerwinprabu @joeQ Or just do

        return;
        

        if you do not use the return value...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • JerwinprabuJ Offline
          JerwinprabuJ Offline
          Jerwinprabu
          wrote on last edited by Jerwinprabu
          #10

          @jsulm @joeQ Thanks for your help. Ya @joeQ given proper sample. I have tried that. Here I have posted the solution now client side that is working fine, one time I want to check from server side. Kindly check, if anything wrong awaiting for your further response

          startvaluexy = Client::straightxy;
          qDebug() << "start xy value Received from server :" << startvaluexy;
          QStringList xy = startvaluexy.split("|");
          int xySize = xy.size(); 
          qDebug() << "start xy size :" << xySize;
          
          if(xySize > 4){
               x = xy[2];
               y = xy[3];
            }
          
               QString num1 = x;
               int x = num1.toInt();
          
               qDebug() << "start x value  :" << x;
          
               QString num2 = y;
               int y = num2.toInt();
          
               qDebug() << "start y value :" << y;
          
              xstart = x;
              ystart = y;
          

          After checking the size will modify this xySize > 4

          jsulmJ 1 Reply Last reply
          0
          • JerwinprabuJ Jerwinprabu

            @jsulm @joeQ Thanks for your help. Ya @joeQ given proper sample. I have tried that. Here I have posted the solution now client side that is working fine, one time I want to check from server side. Kindly check, if anything wrong awaiting for your further response

            startvaluexy = Client::straightxy;
            qDebug() << "start xy value Received from server :" << startvaluexy;
            QStringList xy = startvaluexy.split("|");
            int xySize = xy.size(); 
            qDebug() << "start xy size :" << xySize;
            
            if(xySize > 4){
                 x = xy[2];
                 y = xy[3];
              }
            
                 QString num1 = x;
                 int x = num1.toInt();
            
                 qDebug() << "start x value  :" << x;
            
                 QString num2 = y;
                 int y = num2.toInt();
            
                 qDebug() << "start y value :" << y;
            
                xstart = x;
                ystart = y;
            

            After checking the size will modify this xySize > 4

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #11

            @Jerwinprabu said in ASSERT failure in QList<T>::operator[]: "index out of range":

            if(xySize > 4){

            shouldn't it be

            if(xySize >= 4){
            

            ?
            And if it is not >= 4 what would be the values of x and y? Shouldn't you just skip processing in this case (do return as @joeQ suggested)?

            What are you trying to do with this

            QString num1 = x;
            int x = num1.toInt();
            

            ?! Why do you assign an integer to a string and then convert this string to integer again? Same for

            QString num2 = y;
            int y = num2.toInt();
            

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            JerwinprabuJ 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Jerwinprabu said in ASSERT failure in QList<T>::operator[]: "index out of range":

              if(xySize > 4){

              shouldn't it be

              if(xySize >= 4){
              

              ?
              And if it is not >= 4 what would be the values of x and y? Shouldn't you just skip processing in this case (do return as @joeQ suggested)?

              What are you trying to do with this

              QString num1 = x;
              int x = num1.toInt();
              

              ?! Why do you assign an integer to a string and then convert this string to integer again? Same for

              QString num2 = y;
              int y = num2.toInt();
              
              JerwinprabuJ Offline
              JerwinprabuJ Offline
              Jerwinprabu
              wrote on last edited by
              #12

              @jsulm from server I will receive the string then I want to convert that string into int. Again I want to convert for sending to server(for map).

              jsulmJ 1 Reply Last reply
              0
              • JerwinprabuJ Jerwinprabu

                @jsulm from server I will receive the string then I want to convert that string into int. Again I want to convert for sending to server(for map).

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by jsulm
                #13

                @Jerwinprabu Then why do you convert it back from string to int? x is already int, what's the point to convert from string to int?
                Also

                QString num1 = x;
                

                is not a conversion to string from int! It will not even compile. If you want to convert int to string then do it like shown here http://doc.qt.io/qt-5/qstring.html#number

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                JerwinprabuJ 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Jerwinprabu Then why do you convert it back from string to int? x is already int, what's the point to convert from string to int?
                  Also

                  QString num1 = x;
                  

                  is not a conversion to string from int! It will not even compile. If you want to convert int to string then do it like shown here http://doc.qt.io/qt-5/qstring.html#number

                  JerwinprabuJ Offline
                  JerwinprabuJ Offline
                  Jerwinprabu
                  wrote on last edited by Jerwinprabu
                  #14

                  @jsulm Because I want to take that value to int only xstart, ystart. I want to convert from string to int only. x, y is not int.

                  QString x;
                  QString y;
                  
                  jsulmJ 2 Replies Last reply
                  0
                  • JerwinprabuJ Jerwinprabu

                    @jsulm Because I want to take that value to int only xstart, ystart. I want to convert from string to int only. x, y is not int.

                    QString x;
                    QString y;
                    
                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by jsulm
                    #15

                    @Jerwinprabu Again

                    QString num1 = x;
                    int x = num1.toInt();
                    

                    x already contains the integer value! Now you convert it to string then again to int - it will be same as before.

                    int x = 1;
                    QString num1 = QString::number(x);
                    x = num1.toInt();
                    qDebug() << x;
                    

                    What do you think the last line will print out?
                    Shouldn't it be just

                    QString num1 = QString::number(x);
                    xstart = x;
                    

                    ?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • JerwinprabuJ Jerwinprabu

                      @jsulm Because I want to take that value to int only xstart, ystart. I want to convert from string to int only. x, y is not int.

                      QString x;
                      QString y;
                      
                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #16

                      @Jerwinprabu Also here you redefine the variable x

                      QString num1 = x;
                      int x = num1.toInt();
                      

                      is there a reason why you're doing this?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        After chatting with @Jerwinprabu I realised that I misunderstood his code: x and y are actually QString not int.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        mrjjM 1 Reply Last reply
                        1
                        • jsulmJ jsulm

                          After chatting with @Jerwinprabu I realised that I misunderstood his code: x and y are actually QString not int.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #18

                          @jsulm
                          Well x is a pretty confusing name for a string in most cases.
                          I was sure also it was int.

                          1 Reply Last reply
                          1

                          • Login

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