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

Led Indicator in Qt



  • Hi,
    I want to design led indicator in qt4 i wrote some code cannot work for me
    please find out the bug here the code is:
    @
    void MainWindow::on_pushButton_3_clicked()
    {
    sleep(2);
    green();
    sleep(2);
    red();
    }

    void MainWindow::green()
    {
    ui->pushButton->setIcon(QIcon("/home/ubuntu/green.png"));
    ui->pushButton->setIconSize(QSize(50,50));
    ui->pushButton_2 ->setIcon(QIcon("/home/ubuntu/red_off.png"));
    ui->pushButton_2 ->setIconSize(QSize(50,50));
    }
    void MainWindow::red()
    {
    ui->pushButton->setIcon(QIcon("/home/ubuntu/green_off.png"));
    ui->pushButton->setIconSize(QSize(50,50));
    ui->pushButton_2 ->setIcon(QIcon("/home/ubuntu/red_on.png"));
    ui->pushButton_2 ->setIconSize(QSize(50,50));
    }
    @

    [andreyc EDIT]: Added @ around the code



  • @
    void MainWindow::on_pushButton_3_clicked()
    {
    sleep(2);
    green();
    sleep(2);
    red();
    }
    void MainWindow::green()
    {
    ui->pushButton->setIcon(QIcon("/home/ubuntu/green.png"));
    ui->pushButton->setIconSize(QSize(50,50));
    ui->pushButton_2 ->setIcon(QIcon("/home/ubuntu/red_off.png"));
    ui->pushButton_2 ->setIconSize(QSize(50,50));
    }
    void MainWindow::red()
    {
    ui->pushButton->setIcon(QIcon("/home/ubuntu/green_off.png"));
    ui->pushButton->setIconSize(QSize(50,50));
    ui->pushButton_2 ->setIcon(QIcon("/home/ubuntu/red_on.png"));
    ui->pushButton_2 ->setIconSize(QSize(50,50));
    }
    @
    [andreyc EDIT]: Added @ around the code



  • The code in second post looks the same as in first.

    What problem do you have with this code ?

    I see only one issue so far.
    The sleep() will stop event loop.
    Use QTimer instead.


Log in to reply