Results 1 to 3 of 3

Thread: ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/qbytearray

  1. #1
    Join Date
    Jul 2017
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/qbytearray

    Hi Friends

    I have qtserial port library in my application. my application was previously wriiten in qt4.8.7 with qextserial library.

    Now I did upgrade my application code from qextserial to qserial port library and qt 4.8.7 to qt 5.7.0

    The problem that I faced here is


    Qt Code:
    1. ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464
    To copy to clipboard, switch view to plain text mode 




    So This code works without issue in previous version qt4.8.7 with qextserial port library


    Now I got the error ASSERT : "unit(i) < unint(sisze())


    Help me out to resolve this issue


    My code is here


    My serial port initialize function is here



    Qt Code:
    1. void MainWindow::SerialPortInit()
    2. {
    3. DataAcquisitionPort = new QSerialPort();
    4. DataAcquisitionPort->setPortName("/dev/ttyUSB0");
    5. DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200);
    6. DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl); // To set the flow control to none
    7. DataAcquisitionPort->setDataBits(QSerialPort::Data8);
    8. DataAcquisitionPort->setParity(QSerialPort::NoParity);
    9. DataAcquisitionPort->setStopBits(QSerialPort::OneStop);
    10. qDebug() << "PORT Initialize completed";
    11.  
    12. bool res = DataAcquisitionPort->open(QIODevice::ReadWrite);
    13. connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port()));
    14. if(res)
    15. {
    16. qDebug() << "TRYING TO OPEN PORT";
    17. const char data[] = "PROTOCOL PORT OPEN SUCCESS";
    18. qDebug() << data;
    19. DataAcquisitionPort->write(data, sizeof(data));
    20. const char Protocol_init_data_1[] = { 0x80};
    21. const char Protocol_init_data_2[] = { 0x04 };
    22. const char Protocol_init_data_3[] = { 0x00 };
    23. const char Protocol_init_data_4[] = { 0x80 };
    24. const char Protocol_init_data_5[] = { 0x02 };
    25. const char Protocol_init_data_6[] = { 0x00 };
    26. DataAcquisitionPort->write(Protocol_init_data_1, sizeof(Protocol_init_data_1));
    27. // Sleeper::msleep(100);
    28. QThread::msleep(100);
    29. DataAcquisitionPort->write(Protocol_init_data_2, sizeof(Protocol_init_data_2));
    30. // Sleeper::msleep(100);
    31. QThread::msleep(100);
    32. DataAcquisitionPort->write(Protocol_init_data_3, sizeof(Protocol_init_data_3));
    33. //Sleeper::msleep(100);
    34. QThread::msleep(100);
    35. DataAcquisitionPort->write(Protocol_init_data_4, sizeof(Protocol_init_data_4));
    36. //Sleeper::msleep(100);
    37. QThread::msleep(100);
    38. DataAcquisitionPort->write(Protocol_init_data_5, sizeof(Protocol_init_data_5));
    39. //Sleeper::msleep(100);
    40. QThread::msleep(100);
    41. DataAcquisitionPort->write(Protocol_init_data_6, sizeof(Protocol_init_data_6));
    42. qDebug() << "PROTOCOL OPEN SUCCESS";
    43. }
    44. else
    45. {
    46. qDebug("PROTOCOL PORT OPEN FAILED");
    47. }
    48. }
    To copy to clipboard, switch view to plain text mode 



    And this function for check whether the valid data arrived or not

    Qt Code:
    1. void MainWindow::Get_Data_from_Serial_port()
    2. {
    3. QByteArray Protocol_Raw_Data;
    4. Protocol_Raw_Data = DataAcquisitionPort->readAll().toHex(); // Get the data and convert it to Hex fornat
    5. qDebug() << Protocol_Raw_Data;
    6. if((Protocol_Raw_Data.startsWith("02")) && (Protocol_Raw_Data.endsWith("03"))) // To check for the Complete Frame
    7. {
    8. P1.append(Protocol_Raw_Data);
    9. Protocol_Data_Organize(P1);
    10. P1.clear();
    11. }
    12. else
    13. {
    14. P1.append(Protocol_Raw_Data); // If the frame is not completed, then append the data to Pi array
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 



    And his function for organize the raw data and separate the raw into a single frame

    Qt Code:
    1. void MainWindow::Protocol_Data_Organize(QByteArray Data)
    2. {
    3. QList <QByteArray> Data_Frame;
    4. for(int pos = 0; pos < Data.size(); pos++)
    5. {
    6. if( (Data.at(pos-1) == '0' && Data.at(pos) == '3' && Data.at(pos+1) == '0' && Data.at(pos+2) == '2') || ((Data.at(pos) == '3') && pos == (Data.size()-1)) )
    7. {
    8. Data.insert((pos+1), ';'); // Inserting a Splitter between the individual data frames
    9. }
    10. }
    11. Data_Frame << Data.split(';'); // Splits the Whole data frame into separate individual data frame and stores it in the List
    12. Protocol_Data_split(Data_Frame);
    13. }
    To copy to clipboard, switch view to plain text mode 



    My application code Build and compiled successfully but when i run the code application closed unexpectedly


    Qt Code:
    1. ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464
    2. The program has unexpectedly finished.
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/qbytea

    I think you need to learn to use the debugger. Set breakpoints at the places where you are changing the contents of your QByteArray instances and see if they contain what you think they do. The call stack should tell you exactly where the assert occurs (which may not be where the error is, because something else you do earlier in the code might eventually result in the error that causes the crash).
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2017
    Posts
    58
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/qbytea

    Not sure, is this code correct?
    Qt Code:
    1. for(int pos = 0; pos < Data.size(); pos++)
    2. {
    3. if( (Data.at(pos-1) == '0' && Data.at(pos) == '3' && Data.at(pos+1) == '0' && Data.at(pos+2) == '2') || ((Data.at(pos) == '3') && pos == (Data.size()-1)) )
    4. {
    5. Data.insert((pos+1), ';'); // Inserting a Splitter between the individual data frames
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. inline char QByteArray::at(int i) const
    2. { Q_ASSERT(uint(i) < uint(size())); return d->data()[i]; }
    To copy to clipboard, switch view to plain text mode 

    Especially in the first cycle, when pos = 0. Then in the if condition you are trying to get Data.at(0-1) what means -1 position, this might be the error. Also in the for the last value of pos, when pos = Data.size()-1, then you are trying to get pos+2 what does not exist.

    Maybe this can help:
    Qt Code:
    1. for(int pos = 1; pos < Data.size()-2; pos++)
    To copy to clipboard, switch view to plain text mode 
    Last edited by ado130; 31st July 2018 at 08:03.

Similar Threads

  1. Replies: 1
    Last Post: 2nd November 2016, 00:02
  2. Replies: 2
    Last Post: 2nd March 2015, 16:27
  3. Replies: 10
    Last Post: 29th August 2014, 10:02
  4. Replies: 1
    Last Post: 5th February 2011, 22:14
  5. (portion of...) QByteArray to UInt
    By pdoria in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2009, 16:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.