Solved Loop not working
-
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! -
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.
-
@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. -
@sowas good catch ! The blocking loop pattern made me miss that part.