Important: Please read the Qt Code of Conduct -

Resizing window blocks serialPort bot not the timer

  • Hi,

    I'm developing an application to communicate with a robot via Bluetooth. Everything works fine, but when I resize or move an application window, slot connected to readyRead() is not being called. That would not be a terrible problem, but I also have a method to constantly monitoring the connection. When no data are read in certain period it assumes that the connection was lost, pops up a warning and closes the serial port. The method is fired by the timer timeout, which occurs even if I move a window, causing app to close the connection (because no data are read meanwhile).

    I do not use multihreading, relying only on signals and slots. How can I cause both methods to be executed during GUI operations, or both to be halted?

    @ //method fired by the timer
    void BoardConnection::pingBoard()
    if(connectionAlive) {
    } else {
    emit connectionLost();

    connectionAlive = false;


    // method connected to readyRead() slot
    void BoardConnection::readData()
    connectionAlive = true;
    QByteArray data = connection.readAll();
    // process stuff

  • I have noticed some odd things with QSerialPort myself. It seems to be always related to the event loop in one way or another.

    I have a suggestion for a work around (not a solution). You can detect when your window is changing size or moving (override associated events) and when this is happening you can ignore your timer to shut down the serial port.

  • That's exactly what I am doing right now. But , as you said, it's just a workaround, not a solution. There is also a risk, that I will overlook some event (for example I have just found out, that not only main window resize or move hangs QSerialPort, but also dragging of default window status bar).

  • Qt Champions 2020


    This fixed in future Qt 5.5 (but never will be fixed when uses Qt 4.x):

    So, just use the QSerialPort in another thread (by using the moveToThread() method) or to wait up to Qt5.5 released.

  • I was hoping to avoid multithreading somehow. Well, thanks for help anyway!

Log in to reply