Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal and slot problem
Qt 6.12 LTS is out! See what's new in the release blog

Signal and slot problem

Scheduled Pinned Locked Moved Solved General and Desktop
30 Posts 4 Posters 23.3k Views 2 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.
  • ? Guest
    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #10

    Ok, if u create a instance for use with signals, then its fine.
    You just need to connect this new object to the slots again.

    ? 1 Reply Last reply
    0
    • mrjjM mrjj

      Ok, if u create a instance for use with signals, then its fine.
      You just need to connect this new object to the slots again.

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #11

      @mrjj thanks but i'm pretty much beginner with signals and slots,where do i need to change my code

      mrjjM 1 Reply Last reply
      0
      • ? A Former User

        @mrjj thanks but i'm pretty much beginner with signals and slots,where do i need to change my code

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #12

        @azravian
        Hi,
        void gpio::ISR()
        {
        gpio* GPIO=new gpio;
        // here u need to connect again
        // since its not pr type, but pr instance
        // so the connect u made in main, are not on GPIO here

        ? 1 Reply Last reply
        0
        • mrjjM mrjj

          @azravian
          Hi,
          void gpio::ISR()
          {
          gpio* GPIO=new gpio;
          // here u need to connect again
          // since its not pr type, but pr instance
          // so the connect u made in main, are not on GPIO here

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #13

          @mrjj thank you it worked thank you so much Sir :)

          mrjjM 1 Reply Last reply
          1
          • ? A Former User

            @mrjj thank you it worked thank you so much Sir :)

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #14

            @azravian
            Super, np :)
            sorry I missed ur static function. The scroll area is so tiny .)

            ? 1 Reply Last reply
            0
            • mrjjM mrjj

              @azravian
              Super, np :)
              sorry I missed ur static function. The scroll area is so tiny .)

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #15

              @mrjj
              Oh it's Ok sir, thanks Again for your input and help :) I've surely learned a lot

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

                Hi,

                Just one thing, you have now a memory leak.

                But in any case, I must say I don't see any reason for making all these methods static.

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

                mrjjM ? 2 Replies Last reply
                0
                • SGaistS SGaist

                  Hi,

                  Just one thing, you have now a memory leak.

                  But in any case, I must say I don't see any reason for making all these methods static.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #17

                  @SGaist
                  Thank champ. In the static heat, i completely missed that.

                  @azravian
                  You should have a
                  delete GPIO in the end of the function or even better
                  just go back to using the stack again. (so it cleans it self)
                  void gpio::ISR()
                  {
                  gpio GPIO;

                  ? 2 Replies Last reply
                  0
                  • mrjjM mrjj

                    @SGaist
                    Thank champ. In the static heat, i completely missed that.

                    @azravian
                    You should have a
                    delete GPIO in the end of the function or even better
                    just go back to using the stack again. (so it cleans it self)
                    void gpio::ISR()
                    {
                    gpio GPIO;

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by A Former User
                    #18

                    @mrjj @SGaist
                    Yes i noticed it later and have deleted it. thanks again sir

                    1 Reply Last reply
                    1
                    • SGaistS SGaist

                      Hi,

                      Just one thing, you have now a memory leak.

                      But in any case, I must say I don't see any reason for making all these methods static.

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #19

                      @SGaist thank you for it :) and the point od making these methods statics is that i am using wiringPi library which need a function as a parameter so i need make it static.

                      jsulmJ 1 Reply Last reply
                      0
                      • ? A Former User

                        @SGaist thank you for it :) and the point od making these methods statics is that i am using wiringPi library which need a function as a parameter so i need make it static.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #20

                        @azravian In this case you could add a public static method to get the pointer to the gpio instance (basically you create a singleton):

                        class gpio : public QObject
                        {
                            Q_OBJECT
                        public:
                            gpio(): instancePtr(nullptr) {}
                            static gpio* instance()
                            {
                                if (!instancePtr) instancePtr = new gpio();
                                return instancePtr;
                            }
                        private:
                            gpio* instancePtr;
                        

                        You can use this method in main to setup the connection and in static methods in gpio to get the pointer to the instance. Don't forget to delete the instance later.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

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

                          @jsulm you forgot to also make instancePtr static. However, I don't think the singleton pattern should be applied here.

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

                          jsulmJ 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            @jsulm you forgot to also make instancePtr static. However, I don't think the singleton pattern should be applied here.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #22

                            @SGaist Yes, I forgot, thanks for pointing :-)

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @SGaist
                              Thank champ. In the static heat, i completely missed that.

                              @azravian
                              You should have a
                              delete GPIO in the end of the function or even better
                              just go back to using the stack again. (so it cleans it self)
                              void gpio::ISR()
                              {
                              gpio GPIO;

                              ? Offline
                              ? Offline
                              A Former User
                              wrote on last edited by
                              #23

                              @mrjj @SGaist
                              Now it's all working now but i cannot use ui memeber like label, lineEdit etc. For example

                              void MainWindow::inserted()
                              {
                                  qDebug()<<"Inserted...";
                                  ui->label->setText("Inserted");
                              }
                              

                              i do get "Inserted..." but the label does not change Text :(

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

                                Silly question but are you user the label is visible ? Do you have something on it before you call inserted ?

                                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
                                • SGaistS SGaist

                                  Silly question but are you user the label is visible ? Do you have something on it before you call inserted ?

                                  ? Offline
                                  ? Offline
                                  A Former User
                                  wrote on last edited by
                                  #25

                                  @SGaist yes for instance it has the default text "textLabel" and that's visible on GUI

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

                                    Then do you have something else that modifies that label ?

                                    Things would be a bit easier if there was a possibility to see your code.

                                    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
                                    • SGaistS SGaist

                                      Then do you have something else that modifies that label ?

                                      Things would be a bit easier if there was a possibility to see your code.

                                      ? Offline
                                      ? Offline
                                      A Former User
                                      wrote on last edited by
                                      #27

                                      @SGaist
                                      Sure Sir, it's the same code except i added just one line

                                      #include "mainwindow.h"
                                      #include "ui_mainwindow.h"
                                      #include "gpio.h"
                                      #include <QDebug>
                                      
                                      bool firstTime=true;
                                      MainWindow::MainWindow(QWidget *parent) :
                                          QMainWindow(parent),
                                          ui(new Ui::MainWindow)
                                      {
                                          if(firstTime)
                                          {
                                              gpio::Initialize();
                                              firstTime=false;
                                          }
                                          gpio* GPIO=new gpio;
                                          connect(GPIO,SIGNAL(RisingEdge()),this,SLOT(inserted()));
                                          connect(GPIO,SIGNAL(FallingEdge()),this,SLOT(Removed()));
                                          delete GPIO;
                                          ui->setupUi(this);
                                      }
                                      
                                      MainWindow::~MainWindow()
                                      {
                                          delete ui;
                                      }
                                      void MainWindow::inserted()
                                      {
                                          qDebug()<<"Inserted...";
                                          ui->label->setText("Inserted");
                                      }
                                      
                                      void MainWindow::Removed()
                                      {
                                          ui->label->setText("Inserted");
                                          qDebug()<<"Removed...";
                                      }
                                      
                                      
                                      
                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #28

                                        If I may, you really should first cleanup your gpio class. It looks wrongly implemented and is wrongly used.

                                        Make it a normal object i.e. don't use any static in it and don't make it a singleton. Once you have that sorted, it will be easier to integrate it in your GUI.

                                        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
                                        • SGaistS SGaist

                                          If I may, you really should first cleanup your gpio class. It looks wrongly implemented and is wrongly used.

                                          Make it a normal object i.e. don't use any static in it and don't make it a singleton. Once you have that sorted, it will be easier to integrate it in your GUI.

                                          ? Offline
                                          ? Offline
                                          A Former User
                                          wrote on last edited by A Former User
                                          #29

                                          @SGaist
                                          if i don't use ISR() and Initialize() as static i get error with wiringPiISR()
                                          as
                                          wiringPiISR (BUTTON, INT_EDGE_BOTH,&ISR);
                                          it gives an error
                                          error: cannot convert 'void (gpio::)()' to 'void ()()' for argument '3' to 'int wiringPiISR(int, int, void (*)())'
                                          wiringPiISR (BUTTON, INT_EDGE_BOTH,&ISR);
                                          ^

                                          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
                                          • Unsolved