Two Way Button Problem



  • Hi all,
    Sorry for noob question but i'm a newbie with qt and C++ isn't my primary language.
    I've created in Qt Design a button named ResistenzeOn, with a slot clicked(); .
    In my mainwindow.h i've declared this :

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QtGui>
    #include <QSize>
    #include <QDebug>
    #include <QMainWindow>
    #include <QMessageBox>
    #include <QWidget>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);

    QState *off;
    QState *on;
    QStateMachine machine;
    
    
    
    ~MainWindow();
    

    private slots:

    void on_ResistenzeOn_clicked();
    

    private:

    Ui::MainWindow *ui;
    

    };

    #endif // MAINWINDOW_H

    In mainwindow.cpp:

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    off = new QState();
    off->assignProperty(ui->ResistenzeOn,"text","On");
    off->setObjectName("off");
    
    on = new QState();
    on->assignProperty(ui->ResistenzeOn,"text","Off");
    
    off->addTransition(ui->ResistenzeOn, SIGNAL(on_ResistenzeOn_clicked()), on);
    on ->addTransition(ui->ResistenzeOn, SIGNAL(on_ResistenzeOn_clicked()), off);
    
    machine.addState(off);
    machine.addState(on);
    
    machine.setInitialState(off);
    machine.start();
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_ResistenzeOn_clicked()
    {

    gpioWrite(OUT_RES, 1);
    ui->labelResistence->setPixmap(MainWindow::fireScaled);
    

    }

    But when i run the program the output is :
    QState::addTransition: no such signal QPushButton::on_ResistenzeOn_clicked()

    I cannot understand where is the problem.
    Ho can i call a specific function based on the button state?
    Thanks,
    Giovanni


  • Lifetime Qt Champion

    Hi,

    on_ResistenzeOn_clicked is not a signal but a slot that will be automatically connect to your button when ui->setupUi(this) is called. What you want to connect to your states is the button's clicked() signal.



  • SGaist, thanks a lot,
    but how can i specify which function is called when the transition occur?
    Thanks,
    Giovanni


  • Lifetime Qt Champion

    What function would you like to call ?



  • @SGaist : Thanks for your time.
    I have a function that set to ON or OFF a PIN using PIGPIO:

    gpioWrite(pinNumber, level);

    When i click and the state go to off i need to call gpioWrite(21,0); when go to on i will call gpioWrite(21,1);

    Thanks.
    Giovanni


  • Lifetime Qt Champion

    Do you have a dedicated object that handles the GPIOs ?

    In any case you can use two slots, one for each state that you can connect to the corresponding state's entered signal.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.