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_OBJECTpublic:
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 -
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'sclicked()
signal. -
What function would you like to call ?
-
-
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.