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. Loop not working
Forum Updated to NodeBB v4.3 + New Features

Loop not working

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 302 Views 2 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.
  • A Offline
    A Offline
    Anturaju93
    wrote on last edited by
    #1

    Hi.
    I'm new to QT and I'm trying to create a project for school using QT and Arduino. I want to send signals to a RGB LED in a loop when I push a button, to light up the LED colors one after another, but the code in the loop does not work:

    void Dialog::on_pushButton_pressed()
    {
        buclaLeduri();
    }
    
    void Dialog::buclaLeduri(){
        int i = 1;
        while(i>=10){
            Dialog::updateRGB(QString("r%1").arg(ledAprins));
            qDebug() << ledAprins;
            Sleep(500);
            Dialog::updateRGB(QString("r%1").arg(ledStins));
            qDebug() << ledStins;
            Sleep(500);
            i++;
        }
    }
    

    Any help, please?
    Thanks!

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

      Hi and welcome to devnet,

      You are blocking the event loop which is always a wrong idea. Use a QTimer to trigger what you want at regular interval.

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

      S 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        You are blocking the event loop which is always a wrong idea. Use a QTimer to trigger what you want at regular interval.

        S Offline
        S Offline
        sowas
        wrote on last edited by
        #3

        @SGaist
        the loop will never work, as it can not start when i = 1, and
        the start condition is (i > 10), 1 is not equal or bigger than 10.

        SGaistS 1 Reply Last reply
        5
        • S sowas

          @SGaist
          the loop will never work, as it can not start when i = 1, and
          the start condition is (i > 10), 1 is not equal or bigger than 10.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @sowas good catch ! The blocking loop pattern made me miss that part.

          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