Worker thread is blocking gui after upgrade from 5.9.2 to 5.10.1



  • Hi!

    When my worker thread is writing a new logfile, my gui hangs for 3-4 seconds. This was solved by moving the logfile writer class to a second thread.

    Suddeny the issue came back and after debugging the code, I realize that the point where it starts to hang again is when I upgraded the Qt sdk to 5.10.1. The relevant code is the same.

    Any suggestions on why it behaves like this with the new Qt version?

    Here is a simplified, sample code showing how I use the logfile writer with QThread:

    LogController::LogController(QObject *parent)
        : QObject(parent)
    {
        m_logWriterThread = new QThread(this);
        m_logFileWriter = new LogFileWriter;
        m_isLogging = false;
    
        m_logFileWriter->moveToThread(m_logWriterThread);
    
        connect(m_logWriterThread, SIGNAL(finished()), m_logFileWriter, SLOT(deleteLater()) );
    
        connect(this, &LogController::writeLogToZip, m_logFileWriter,
                &LogFileWriter::write, Qt::QueuedConnection);
    
        m_logWriterThread->start();
    }
    
    void LogController::onNewDataArrived(const QVector<double>& data)
    {
        if (m_isLogging == true) {
            
            //Fill container with data...
    
            ++m_currentSample;
    
            //Update progress bar every 100 cycles
            if (m_currentSample % 4 == 0) emit updateProgressBar(m_currentSample);
    
            //Check if it is time to write and start a new log
            if (m_currentSample >= m_samplesPrFile) {
              
                m_currentSample = 0;
                m_timeAxisValDiff = 0.0;
    
                emit writeLogToZip(the new filled up data); //Blocks when logfilewriter is working
            }
        }
    }
    


  • Hi,
    Can you check your function LogFileWriter::write is running in another thread by putting some debug messages ?
    Something like :

    //LogController constructor
    qDebug() << "LogController:LogController() - thread id: " << QThread::currentThreadId();
    
    //LogFileWriter::write()
    qDebug() << "LogFileWriter::write() - thread id: " << QThread::currentThreadId();
    


  • Yes, I did that yesterday, but with this->thread(); instead of QThread::currentThreadId();

    Result yesterday was unique address on the logFileWriter thread, result now:

    MainWindow::MainWindow() - thread id:  0x3bc4 , this->thread():  QThread(0x24c8368)
    LogController::LogController() - thread id:  0x3bc4 , this->thread():  QThread(0x24c8368) (as expected)
    LogFileWriter::write() - thread id:  0x3e24 , this->thread():  QThread(0x1f287480)
    

    Now I'm a bit confused: To compile qDebug with QThread::currentThreadId, i needed to include QDebug, and when I tested while running the debug statements my issue where gone.
    Did a second test without the include and qDebug's, and still works great, my realtime data plots smoothly also when the logfile is written.

    So it's solved, but with no clue on what the problem was...



  • That's very strange. But if you are sure that's you didn't change anything in your code, maybe this means that something went wrong with your first compilation.
    As it makes not sense that changing Qt version from 5.9 to 5.10 can cause this behavior, I think that you can probably consider this as fixed. But I'm not familiar with tree view modeling so I hope there is not any hidden bug remaining.



  • @Gojir4 said in Worker thread is blocking gui after upgrade from 5.9.2 to 5.10.1:

    hat's very strange. But if you are sure that's you didn't change anything in your code, maybe this means that something went wrong with your first compilation.
    As it makes not sense that changing Qt version from 5.9 to 5.10 can cause this behavior, I think that you can probably consider this as fixed. But I'm not familiar with tree view modeling so I hope there is not any hidden bug remaining.

    I'm pretty sure, I retrieved a version commited at a point where I now it works, a working backup. And experienced the same. The issue has been there for a couple of weeks, but I have busy with completing other features of application. I have re-compiled many times and even buildt in a different folder location.

    Anyways, thanks for your help. I will update here if I discover any concrete reason for the problem.



  • @Cute Maybe this can help: https://wiki.qt.io/Model_Test


Log in to reply
 

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