Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Two Way Button Problem
Forum Updated to NodeBB v4.3 + New Features

Two Way Button Problem

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 2 Posters 1.2k Views 1 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.
  • C Offline
    C Offline
    ciclonite
    wrote on last edited by ciclonite
    #1

    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

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

      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.

      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
      • C Offline
        C Offline
        ciclonite
        wrote on last edited by
        #3

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

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

          What function would you like to call ?

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

          C 1 Reply Last reply
          0
          • SGaistS SGaist

            What function would you like to call ?

            C Offline
            C Offline
            ciclonite
            wrote on last edited by
            #5

            @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

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

              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.

              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