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: "uint(i) < uint(size())" qbytearray error
Qt 6.11 is out! See what's new in the release blog

ASSERT: "uint(i) < uint(size())" qbytearray error

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 5.0k Views 1 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.
  • R Offline
    R Offline
    rzizanie
    wrote on last edited by
    #1

    Hello,

    I think there's something wrong in my code because sometimes it throw and ASSERT error :

    QList<int> QlChannelSerial::readBytes() {

    QList<int> *l = new QList<int>();
    QList<int> err({1,1});
    QByteArray buff = QByteArrayLiteral("0000");
    
    if (port_->isOpen() ){
    
        if(port_->waitForReadyRead(2000))
        {
    
            do
            {
                buff = port_->readAll();
                while(port_->waitForReadyRead(100))
                {
                    buff +=port_->readAll();
                }
    
                for (int i=0; i<buff.size(); i++)
                {
                    l->append(buff.at(i));
                }
    
                if(buff.at(0) != 'M' && buff.at(1) != 'P' && buff.at(121) != '$' && buff.at(122) != 'G' && buff.at(123) != 'P' && buff.at(124) != 'R')
                {
                    return err;
                }
    
            }
            while(buff.at(0) != 'M' && buff.at(1) != 'P' && buff.size() < 5);
    
         return *l;
    
        }
    
    
    }
    

    What i'm trying here is to read a Serial Buffer but since it's UART, so not synchrone i want to copy it from zero at exact beginning.

    i'm receiving those data in qml and show them in differents textbox...

    the "err" variable is here to repeat the readBytes() if i didn't receive the correct UART string in order (which is very dirty way i think, but i don't see how to fill my buffer correctly with so randoms reading from Serial)

    Thank you for helping

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

      Hi,

      One strange thing here:

      buff.at(0) != 'M' && buff.at(1) != 'P' && buff.at(121) != '$' && buff.at(122) != 'G' && buff.at(123) != 'P' && buff.at(124) != 'R'

      You don't even check that your buffer is large enough to access these positions.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        It's not just "strange", it's the reason for the ASSERT. I can guess from the text that Qt is checking each QByteArray access to ensure the index (i) is less than than the current content size (size()). If you check buff.size() you'll find it's less than 124.

        1 Reply Last reply
        4
        • R Offline
          R Offline
          rzizanie
          wrote on last edited by
          #4

          thank you, i sometimes got random values but now it doesn't crash anymore

          solved.

          jsulmJ 1 Reply Last reply
          0
          • R rzizanie

            thank you, i sometimes got random values but now it doesn't crash anymore

            solved.

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

            @rzizanie But you still should check the range - always!

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

            1 Reply Last reply
            4

            • Login

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