Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Application freezes all threads until mouse is moved or button pressed

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

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 415 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jobusch
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jobusch
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved