Important: Please read the Qt Code of Conduct -

QextSerialPort missing data [solved]

  • Hi all,

    I'm using QextSerial port to read data from RS-232 at 400hz rate, most of the time I got currected data but sometimes I got invalid data (missing lines from the packet).

    I checked the device with realTerm and the data is currect so it's not a hardware bug.

    what can cose this missing line error? some suggestions?

    More info:

    The algo:
    If (start recording)

    1. clear buffer
    2. read data and sync on the packet header
    3. check sum
    4. save data to files
      if (stop recording)
    5. read data (clear buffer)

    My setup
    QT 4.7
    QextSerialPort 1.2.0
    Win xp sp3
    using sea-level (rs-232 to usb)

    Open port function:

    Source code
    port = new QextSerialPort(portName,QextSerialPort::EventDriven);
    if(port->open(QIODevice::ReadWrite )) {
    connect( port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    else {
    return -1;

    port->setRts( true );
    port->setDtr( true );
    connect(&timer, SIGNAL(timeout()), this, SLOT(procTimerOut()));
    return 0;


    Reading from port:

    #define PACKET_SIZE 40

    void Driver::onReadyRead()
    {/* Read data from port */
    if (this->state() == STOP_RECORDING) {

    if (this->rxBuffer.isEmpty()) {
    QByteArray data = this->port->read(port->bytesAvailable());

    void Driver::procTimerOut()
    /* Print raw data to file */
    if (!this->last_line.isEmpty()){
    if (rxBuffer.size() < PACKET_SIZE) {
    qDebug("buffer is small [%d]",rxBuffer.size());
    if (this->sync(rxBuffer) != SUCCESS) {
    emit actionDone(EINVAL,"Cannot sync on packet");

    while (rxBuffer.size() > PACKET_SIZE) {
        const QByteArray sample = rxBuffer.mid(0, PACKET_SIZE);
        rxBuffer.remove(0, PACKET_SIZE);
        if (this->addSample(sample) == INVALID_CHECKSUM)  {
                QString errMsg = this->portID + ": Invalid checksum at ["
                                 + QString::number(this->sampleCounter) + "]\n"
                                 + QString(sample.toHex());
                emit actionDone(INVALID_LINE,errMsg);
    if (!rxBuffer.isEmpty()) {
        this->last_line = rxBuffer;   //read all data that left
        rxBuffer.clear();             //remove all data that left
    else {

    int Driver::sync(QByteArray &rxBuffer)
    if (!rxBuffer.startsWith(this->key)){//Note: Sync on packet
    int prefix_offset = rxBuffer.indexOf(this->key);
    if (prefix_offset == -1){
    return EINVAL;
    if (!rxBuffer.startsWith(this->key)) {
    return EINVAL;
    return SUCCESS;
    inline int Driver::addSample(const QByteArray & sample)
    const struct packet *pkt;
    pkt = (const struct packet *)sample.constData();
    int checksum_bytes = sizeof(struct packet) - sizeof(pkt->checksum);
    u16 crc = checksum((const unsigned char *)pkt, checksum_bytes);
    if ( crc != pkt->checksum ) {
    return SUCCESS;

    void Driver::startRecording()
    void Driver::stopRecording()

    void Driver::prepareForRecord()
    this->genetate_output_Files(); //creat output files, and open to write data
    //reset data
    QByteArray buf;
    do {
    buf = port->readAll();
    } while (buf.size() > 0);

  • Hello,

    • Maybe you can give a try to QextSerialPort::Polling mode with a QTimer in order to see whether this issue still exists.

    • If you are using Qt SDK which does not contains a qwineventnotifier_p.h under the "include/QtCore/private" directory, QextWinEventNotifier will be used. If so, you can disable this by coping qwineventnofifier_p.h form src\corelib\kernel to that directory.


  • Hello Debao,
    Thanks for your replay.

    I tried to use the QextSerialPort::Polling mode with a QTimer before and it still miss data.

    About the qwineventnotifier_p.h file, I do have it at the “include/QtCore/private” directory.

    I got lack of understanding about what can cause this issue.
    Need help.

  • Need help anyone?

  • Hi,

    I have submitted a bug several day ago, but seems that others do not come with the similar problem.

    So I do not how to do with this.

    However, I found a similar issue at stackoverflow which has been solved.

    You can give a try to it.


  • Hi all,

    want to use RS232 interface in QtCreator under windows at first,
    but i can not find a appropriate library.

    Do anybody have some information obout this?


  • welcome to devnet

    There are at least two different Qt-based implementations available. There have been already a number of threads concerning the topic. One of the implementations or also both are mentioned in following threads with following tags:
    A good start might be "this overview":

  • Thanks koahing very much,

    for the information, I knowed about "QExtSerialPort", but the QSerialDevice can be the right for my project.

  • 2 Dantcho

    bq. but the QSerialDevice can be the right for my project

    Instead of QSerialDevice - use "QtSerialPort":
    QSerialDevice is no longer growing (develop is freezing). His code was used as the basis QtSerialPort. Now QtSerialPort is a child.

  • Hi all,

    I have to work with serial port and need to to install it on my computer.
    What i have to do to install it?

    I download this:

    from here:

    but I am a little confuse because the installing guide is for linux not for windows.
    How to install qt serial port on windows?


  • What an embarrassment? Where does it say that only for Linux?

    Read "it": again

  • Hi everybody,

    i develop a programm and i want my widget do not be moved by the mouse(press and drag), the widget must stay always on the same position.
    How can i do this?


  • Hi everybody,

    I createt tree windows with the QtDesigner and from windows one of them start the another windows,
    from windows one I have connection to the another windows (include the header files), so I include the the header file from the windows one to the another windows to have connection from every window to the window one, but wenn I declare filetype from windows one I get the following error.
    "Fehler:ISO C++ forbids declaration of 'Com_Net' with no type"

    this is a C++ error, but I include the header files :-(((.

    Wath cann I do to solve this problem.

    Here is the header file from the another windows.

    @#ifndef DICS_H
    #define DICS_H

    #include <QWidget>
    #include <QSizePolicy>
    #include <QMoveEvent>

    #include "com_net.h" bq. here include the header files from the windows one
    #include "ui_com_net.h"

    namespace Ui {
    class DICS;

    class DICS : public QWidget

    explicit DICS(QWidget *parent = 0);

    private slots:
    void on_External_Button_clicked();
    void on_Internal_Button_clicked();
    void on_PABX_Button_clicked();
    void on_PAS_Button_clicked();

    Ui::DICS *ui;
    Com_Net *active_com_net; bq. and here is the pointer declaration from windows one.
    virtual void moveEvent(QMoveEvent *event);

    #endif // DICS_H@

    Thanks very much, for the help.

  • Hallo everybody,

    i solved this problem with the type visibility.

  • Moderators

    Be sure and edit your original post title to add [Solved]. Thanks!

  • Dear community,

    I work with the "qextserialport-1.2beta2" and all work well, but I have one problem, I want to send in binary mode, ones I can set is "port->setTextModeEnabled(false);" but the serial port stil interpret the data "o" like a null terminator and so cut the string after the every "0".
    my question is it possible to send by "qextserialport" binary mode, or I have to look for a another way.

    thanks for the answer, :-))).

Log in to reply