Important: Please read the Qt Code of Conduct -

QSerialPort dont emitted readyRead if window is resizing or moving

  • Hello, help me, please.

    I have class for work with some device by COM port. But it dont emitted readyRead if i'm resizing or moving program's window. How solve this problem?

    @class Device : public QObject

    explicit Device(QObject *parent = 0);
    bool openPort(const QString &portName);
    void closePort();
    bool isPortOpen() const;
    bool sendCommand(unsigned char cmd, unsigned char arg = 0);
    bool connectDevice();

    private slots:
    void onReadData();
    void error(QSerialPort::SerialPortError error);

    QSerialPort *port;
    QByteArray buffer;

    void newDataAvailbled(CurrentData* data);

    @Device::Device(QObject *parent) : QObject(parent)
    this->port = new QSerialPort(this);
    connect(this->port, SIGNAL(readyRead()), this, SLOT(onReadData()));

    delete this->port;

    bool Device::openPort(const QString &portName)
    const bool isOpen = this->port->open(QIODevice::ReadWrite);
    if (isOpen == true) {
    return isOpen;

    void Device::closePort()
    if (this->port->isOpen())

    bool Device::isPortOpen() const
    return this->port->isOpen();

    bool Device::sendCommand(unsigned char cmd, unsigned char arg)
    if (this->isPortOpen() == false)
    return false;
    QByteArray buf;
    if (this->port->write(buf) != buf.size())
    return false;
    return true;

    bool Device::connectDevice()
    return this->sendCommand(DeviceCommands::TurnOffSMode);

    void Device::onReadData()
    emit this->newDataAvailbled(newData);

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    I would say that the event loop is "blocked" processing the resizing hence the readyRead are not processed while your moving your window. You could move Device in another thread.

    QThread *serialThread = new QThread(this);
    Device *device = new Device;
    // do connections etc...

    Something like that

    Hope it helps

  • Qt Champions 2020

    Yes, SGaist is right.

    At present the single decision is use of a separate thread. But in the future (for Qt >= 5.x only) is planned to use I/O completion port feature for resolve this problem (but it just ideas on the future).

  • I used moveToThread(), but problem was left((
    I'm use windows 7 and Qt5.1

    also, if connected readyRead to slot in Device by Qt:AutoConnection, then I have Heap Corruption on reading data. if connect by DirectConnection or BlockingQueuedConnection, then it's OK, but problem with moving of window was left

  • So...
    I moved method from signal from readyRead() to timerEvent...
    @void Device::timerEvent(QTimerEvent *)
    int c = port->bytesAvailable();
    emit testSignal(QTime::currentTime().toString() + " " + QString::number(c));

    and if I'm moving window, then c is zero, but signal was emitted and I getting current time and zero

  • sorry, I forgot waitForReadyBytes

Log in to reply