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. Qt-creator problem: error: 'gpio26' was not declared in this scope
Qt 6.11 is out! See what's new in the release blog

Qt-creator problem: error: 'gpio26' was not declared in this scope

Scheduled Pinned Locked Moved Mobile and Embedded
16 Posts 4 Posters 9.7k 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.
  • M Offline
    M Offline
    Moster
    wrote on last edited by
    #2

    It obviously cant know what gpio26 is. That pointer is only available in your main function

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoergSH
      wrote on last edited by
      #3

      How can I make it usable in slot of my buttons ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Moster
        wrote on last edited by
        #4

        Put it into your LEDcontrol.h

        ledcontrol.h
        @#ifndef LEDCONTROLL_H
        #define LEDCONTROLL_H

        #include <QMainWindow>
        #include "GPIOClass.h"

        namespace Ui {
        class LedControll;
        }

        class LedControll : public QMainWindow
        {
        Q_OBJECT

        public:
        explicit LedControll(QWidget *parent = 0);
        ~LedControll();

        private slots:
        void on_Button_LED_on_clicked();

        void on_Button_LED_off_clicked();
        

        private:
        Ui::LedControll ui;
        GPIOClass
        gpio26;

        };

        #endif // LEDCONTROLL_H
        @

        ledcontroll.cpp

        @#include "ledcontroll.h"
        #include "ui_ledcontroll.h"
        #include "GPIOClass.h"
        #include <iostream>
        #include <unistd.h>
        #include <errno.h>
        #include <stdio.h>
        #include <stdlib.h>
        #include <signal.h>
        using namespace std;

        LedControll::LedControll(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::LedControll)

        {

        gpio26 = new GPIOClass("26"); //create new GPIO object to be attached to  GPIO4
        
        
        gpio26->export_gpio(); //export GPIO26
        
        
        gpio26->setdir_gpio("out"); //GPIO26 set to output
        
        ui->setupUi(this);
        

        }

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

        void LedControll::on_Button_LED_on_clicked()
        {
        gpio26->setval_gpio("1"); // turn LED ON
        }

        void LedControll::on_Button_LED_off_clicked()
        {
        gpio26->setval_gpio("0");
        }
        @

        main.cpp

        @#include "ledcontroll.h"
        #include <QApplication>

        int main(int argc, char *argv[])
        {

        QApplication a(argc, argv);
        LedControll w;
        w.show();
        
        
        
        
        return a.exec&#40;&#41;;
        

        }
        @

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JoergSH
          wrote on last edited by
          #5

          Thank You very much.
          Works fine now !

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JoergSH
            wrote on last edited by
            #6

            One more question.
            The program needs to be root to access gpio. I think thats not the best way. How to change that?

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

              Hi,

              Depending on how the device presents itself, one possibility would be to change the group of the gpio device and add your user to that group

              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
              • J Offline
                J Offline
                JoergSH
                wrote on last edited by
                #8

                I try that but did not realy works.
                I build a group 'hwuser'
                add the user to the group

                change the group with

                chgrp -R hwuser /sys/class

                with ls -l could see that it is done.

                but after reboot the group is root again.

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

                  I thought you were accessing the GPIO through a /dev device or does the sys fs entry point to a device ?

                  Anyway, sys (like /dev in general) is generated dynamically so that method won't work.

                  If you are indeed accessing a device that can be found in /dev, you could try to setup an udev rule that sets the group of that device.

                  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
                  • T Offline
                    T Offline
                    tomma
                    wrote on last edited by
                    #10

                    That is more Linux question than Qt specific. If your target Linux uses udev for device handling then you need to specify rules which states you want "hwuser" group for gpio. Example setting udev-rules for gpio in raspberry pi: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=29&t=9667

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      JoergSH
                      wrote on last edited by
                      #11

                      Ok thanks to all.
                      I figured out now.

                      Thats works for me:
                      sudo nano /etc/udev/rules.d/99-gpio.rules
                      paste:
                      SUBSYSTEM==”gpio”, ACTION==”add”, PROGRAM=”/bin/sh -c ‘chown -R [user]:[group] /sys%p’”
                      PROGRAM=”/bin/sh -c ‘chown -R [user]:[group] /sys/class’”

                      save and reboot

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

                        That might be a little too radical not to say that it's a security breach. Just modify the file you use not the entire tree

                        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
                        • J Offline
                          J Offline
                          JoergSH
                          wrote on last edited by
                          #13

                          ok I will test that.

                          thx

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            JoergSH
                            wrote on last edited by
                            #14

                            it is mysterious,
                            after reboot export gpio works fine but set direction fails.

                            the same again on root works fine.

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

                              Are you accessing several files ?

                              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
                              • J Offline
                                J Offline
                                JoergSH
                                wrote on last edited by
                                #16

                                not sure what You mean.

                                thats the init of the gpio

                                gpio26 = new GPIOClass("26"); //create new GPIO object

                                gpio26->export_gpio(); //export GPIO26
                                
                                
                                gpio26->setdir_gpio("out"); //GPIO26 set to output
                                

                                the export works, I can see it after start program

                                i have made a button to set direction... thats works to

                                i have made button for export unexport and set direction.

                                thats works fine too

                                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