Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Application freezes all threads until mouse is moved or button pressed



  • Hello,
    I have a very strange behaviour I guess I could need some experienced help on.

    So I made a QtWidgets App which communicates with a USB device with libusb and displays some results. In the beginning I spawn a thread which repeatedly uses some function to check if the sensor is still connected. When the user presses a button, the USB device does some work for like 6 seconds and reports the result, while continously updating a progress bar.
    While this work, the spawned thread is not doing anything since I always check in the thread on a variable if the work is ongoing.
    After the work, the spawned thread is frozen. It does not seem to do anything anymore. And that is until I move my mouse or press a key. Instantly the thread is working again as nothing happened.

    I tried std::thread and QThread, it happens with both.

    I'll show you the code of the scanBtnClicked function so maybe you can see if there is something suspicious. I know its bad behaviour that while the scan is running the function does not return. It should be in a separate thread. I am working on this right now to see if it fixes the problem.
    MainWidget inherits from QWidget.

    void MainWidget::on_scan_button_clicked()
    {
        if(!noDoubleClick){
            Ref::isCheckRunning = true;
            ui->products_groupbox->setDisabled(true);
            int errCode;
            ui->scan_button->setEnabled(false);
            ui->continous_scan_button->setEnabled(false);
    
            clearResponse(false);
    
            QApplication::processEvents();
            QByteArray b;
            bool result;
            result = check(&b, !ambilight_check, this, &errCode, active_tdf);
            CheckResponse(result);
            QApplication::processEvents();
            noDoubleClick = true;
            Ref::isCheckRunning = false;
            ui->scan_button->setEnabled(true);
            ui->continous_scan_button->setEnabled(true);
            ui->products_groupbox->setDisabled(false);
            QApplication::processEvents();
    
            QTimer::singleShot(100, this, &MainWidget::resetNoDoubleClick);
        }
    }
    
    void MainWidget::resetNoDoubleClick(){
        noDoubleClick = false;
    }
    

    Any would be really appreciated!
    Best regards,
    Jobusch



  • I fixed it by removing the 2 lines with:

    QApplication::processEvents();
    

    It is still strange behaviour or am I missing something on how QApplication::processEvents() works?

    Best regards,
    Jobusch



  • I fixed it by removing the 2 lines with:

    QApplication::processEvents();
    

    It is still strange behaviour or am I missing something on how QApplication::processEvents() works?

    Best regards,
    Jobusch


Log in to reply