• GpioMonitor
  • GpioMonitor Class

    The GpioMonitor class allows to monitor GPIOs. More...

    Header: #include <GpioMonitor>

    Public Functions

    GpioMonitor(int gpio, QObject * parent = nullptr)
    void disable()
    bool enable(bool activeLow = false, Gpio::Edge edgeInterrupt = Gpio::EdgeBoth)
    Gpio * gpio()
    bool isRunning() const
    bool value() const


    void valueChanged(const bool & value)

    Detailed Description

    The GpioMonitor class allows to monitor GPIOs.

    An instance of this class creates a thread, which monitors each of the added GPIOs. The object emits a signal if one of the added GPIOs changes its value. The GpioMonitor configures a GPIO as an input, with the edge interrupt EDGE_BOTH (setEdgeInterrupt).


    Following example shows how to use the GpioMonitor class for a button on the Raspberry Pi. There are two possibilitys to connect a button. Following picture shows the schematics:

    "Raspberry Pi button example"

    Button A represents a clean solutin with a 10 kΩ resistor (set up as activeLow = false). Button B represents a "dirty" solution, were the 3.3V will be directly connected to the GPIO if the button is pressed (set activeLow = true).

    Here is the code example for a button class:

    Button::Button(QObject *parent) :
        m_button  = new GpioMonitor(110, this);
        connect(m_button, &GpioMonitor::valueChanged, this, &Button::stateChanged);
    bool Button::init()
        return m_button->enable();
    void Button::stateChanged(const bool &value)
        if (m_pressed != value) {
            m_pressed = value;
            if (value) {
                emit buttonPressed();
            } else {
                emit buttonReleased();

    Member Function Documentation

    GpioMonitor::GpioMonitor(int gpio, QObject * parent = nullptr)

    Constructs a GpioMonitor object with the given gpio number and parent.

    void GpioMonitor::disable()

    Disables this GpioMonitor.

    bool GpioMonitor::enable(bool activeLow = false, Gpio::Edge edgeInterrupt = Gpio::EdgeBoth)

    Returns true if this GpioMonitor could be enabled successfully. With the activeLow parameter the values can be inverted. With the edgeInterrupt parameter the interrupt type can be specified.

    Gpio * GpioMonitor::gpio()

    Returns the Gpio of this GpioMonitor.

    bool GpioMonitor::isRunning() const

    Returns true if this GpioMonitor is running.

    bool GpioMonitor::value() const

    Returns the current value of this GpioMonitor.

    [signal] void GpioMonitor::valueChanged(const bool & value)

    This signal will be emitted, if the monitored Gpios changed his value.