'readyread did not emit right in my code in QT5.15.15

Here is my init code.

serial = new QSerialPort(comPort);
serial->setPortName(comPort);
serial->setBaudRate(QSerialPort::Baud38400);
serial->setDataBits(QSerialPort::Data8);
serial->setStopBits(QSerialPort::OneStop);
serial->setParity(QSerialPort::NoParity);
serial->setFlowControl(QSerialPort::NoFlowControl);

connect(serial, &QSerialPort::readyRead, this, &JennicProgrammer::IncomingMessage, Qt::QueuedConnection);
connect(serial, &QSerialPort::errorOccurred, this, &JennicProgrammer::ErrorsHandle);

and here is my serialport operation code:

while(status != CONNECTED) {
    switch(status) {
        case UNCONNECT:
            serial->open(QIODevice::OpenModeFlag::ReadWrite);
            if(serial->isOpen()) {
                serial->setRequestToSend(true);//hold SPI_MISO
                serial->setDataTerminalReady(true);//hold NRST
                QThread::msleep(100);
                serial->setDataTerminalReady(false);//release NRST
                QThread::msleep(100);
                serial->setRequestToSend(false);
                status = CONNECTED;
            }
            break;
        case CONNECTED:
            FormPackageAndSent(GET_CHIP_ID_REQUEST, NULL);
            QThread::msleep(50);
            break;
    }
}

in this case readyread can not emitted,but if i removed the while loop i works fine.did i missed something?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source