QSerialPort and std::bad_alloc

  • Hi,
    I have a serial line which might receive a large quantity of data. Sometimes happens the application crashes with the following output:

    terminate called after throwing an instance of 'std::bad_alloc'
    what(): std::bad_alloc

    it's hard to debug but after a lot of trials it seems it happens during the "readAll" execution:

    void mySerial::readyRead() {
    QByteArray buffer = serial()->readAll();

    The data received is composed of short strings (about 50 byte each) every 10/15 ms.
    If I try to slow down the transmitter (say a string every 50 ms) the crash never happens.

    It's not mandatory to process each single message. I might live with some loss of packets. But I cannot live with such a crash!

    What would you suggest?

  • Whenever you want to read or write large amount of data. then u have to do in parts. means u have to mention that u'll read/write such amount of data in one time and this process will be happened till it is not completed.

  • I process the incoming data as fast as possible. I mean the maximum length I get from readAll is less than 200 byte. I think this is not a very high payload for a x86!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.