Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QT PushButton freeze problem
Qt 6.11 is out! See what's new in the release blog

QT PushButton freeze problem

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sydre
    wrote on last edited by
    #1

    Hello

    I have a small problem with the Push buttons on the QT. If I have a for() loop or do while logic under the push buttons, the cursor is freezing while the logic is not completely executed.

    MainWinfdow.h

    @private slots:
    void on_pushButton_clicked ();
    void on_Blower_ON_Button_pressed();
    int on_Blower_OFF_Button_clicked();@

    With the for() loop cursor is available after it executes all logic inside the loop.

    @void MainWindow::on_pushButton_2_clicked()
    {
    for (int i=0; i<7;i++)
    {

    .....
    }
    }@

    But when I have a do while, it freezes completely making it infinite loop

    @void MainWindow::on_Blower_ON_Button_pressed()
    {

    do
    {
        .....
    }while (on_Blower_OFF_Button_clicked());
    

    }@

    Do I need to initialize the buttons in other way, or is the a specific functions that I need to call to make the buttons non blocking elements.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      It's your while loop that freezes everything. Do you really need that ? What do you do in that loop ?

      Also note that slots don't have return values.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sydre
        wrote on last edited by
        #3

        Yes, do while loop freezes the cursor and program itself. I cannot click any other push button. My idea in this is that I have an on button (with do while loop inside ) and off button to stop doing what it was doing.
        Do while loop is required to make a motor running, because I need to send the same hexadecimal value every 40ms.

        Is it better instead of do while achieve the same result with the interrupts or make a parallel routine?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Way simpler: use either a QTimer or the timerEvent from your widget.

          QTimer:

          configure the timer to use a 40ms interval

          connect the QTimer timeout signal to a custom slot sending the value

          connect your start button to the QTimer start slot

          connect your stop button to the QTimer stop slot

          No loop needed

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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