Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal and slot problem
Forum Updated to NodeBB v4.3 + New Features

Signal and slot problem

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

    @azravian said:
    hi
    first thing to do is to use

    qDebug() <<"con1" << connect(xxx

    for all your connect and check they all return true;

    A 1 Reply Last reply
    0
    • mrjjM mrjj

      @azravian said:
      hi
      first thing to do is to use

      qDebug() <<"con1" << connect(xxx

      for all your connect and check they all return true;

      A Offline
      A Offline
      azravian
      wrote on last edited by
      #3

      @mrjj

      qDebug()<<"Connection Rising edge: "<<connect(GPIO,SIGNAL(RisingEdge()),this,SLOT(inserted()));
          qDebug()<<"Connection falling edge:"<<connect(GPIO,SIGNAL(FallingEdge()),this,SLOT(Removed()));
      

      gives the output

      Connection Rising edge: true
      Connection falling edge: true

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

        @azravian said:
        ok super so they accept the connect.

        your error is here

        void gpio::ISR()
        {
        gpio GPIO; <<<<<<<<<<<<<< that is not the one u connect !?

        That is not the
        gpio* GPIO=new gpio();
        one :)

        Update:
        So when you do
        GPIO.emit_FallingSignal();
        with your local copy, no signal is sent to mainwin as
        its an other instance than the one you new in main.

        A 1 Reply Last reply
        0
        • mrjjM mrjj

          @azravian said:
          ok super so they accept the connect.

          your error is here

          void gpio::ISR()
          {
          gpio GPIO; <<<<<<<<<<<<<< that is not the one u connect !?

          That is not the
          gpio* GPIO=new gpio();
          one :)

          Update:
          So when you do
          GPIO.emit_FallingSignal();
          with your local copy, no signal is sent to mainwin as
          its an other instance than the one you new in main.

          A Offline
          A Offline
          azravian
          wrote on last edited by
          #5

          @mrjj that's seems to be a problem but if i change my ISR()

          void gpio::ISR()
          {
              gpio* GPIO=new gpio;
              if(gpio::isHIGH())
              {
                  qDebug()<<"RISING Interrupt called";
                  GPIO->emit_RisingSignal();
              }
          
              else if(gpio::isLOW())
              {
          
                  qDebug() <<"FALLING edge";
                  GPIO->emit_FallingSignal();
              }
          }
          i have the same problem, it didn't solve the problem/
          
          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            but why are u creating a new Object???
            Use the one in/from main.

            That is the one you have connect to mains slots so making a new one
            in that function will not send any signals to main as you do not connect it
            like the other one.

            So just newing the local copy instead, will not make any difference :)

            mrjjM A 2 Replies Last reply
            0
            • mrjjM mrjj

              but why are u creating a new Object???
              Use the one in/from main.

              That is the one you have connect to mains slots so making a new one
              in that function will not send any signals to main as you do not connect it
              like the other one.

              So just newing the local copy instead, will not make any difference :)

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

              @mrjj

              wait, i just saw
              you create a gpio INSIDE gpio ????

              why?

              mrjjM 1 Reply Last reply
              0
              • mrjjM mrjj

                @mrjj

                wait, i just saw
                you create a gpio INSIDE gpio ????

                why?

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

                I would expect

                void gpio::ISR()
                {

                if(gpio::isHIGH())
                {
                    qDebug()<<"RISING Interrupt called";
                    emit_RisingSignal();
                }
                

                No local object of same type! ?

                1 Reply Last reply
                1
                • mrjjM mrjj

                  but why are u creating a new Object???
                  Use the one in/from main.

                  That is the one you have connect to mains slots so making a new one
                  in that function will not send any signals to main as you do not connect it
                  like the other one.

                  So just newing the local copy instead, will not make any difference :)

                  A Offline
                  A Offline
                  azravian
                  wrote on last edited by
                  #9

                  @mrjj Sir, ISR() is a static function. So to access other functions of the class i need to create an object :) thats why i have defined two other function emit_RisingEdge() and emit_FallingEdge() so i can emit my signals independent of any object.

                  1 Reply Last reply
                  0
                  • ? 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.

                    A 1 Reply Last reply
                    1
                    • 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.

                      A Offline
                      A Offline
                      azravian
                      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 azravian

                        @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

                        A 1 Reply Last reply
                        1
                        • 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

                          A Offline
                          A Offline
                          azravian
                          wrote on last edited by
                          #13

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

                          mrjjM 1 Reply Last reply
                          1
                          • A azravian

                            @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 .)

                            A 1 Reply Last reply
                            1
                            • mrjjM mrjj

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

                              A Offline
                              A Offline
                              azravian
                              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 A 2 Replies 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.

                                  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;

                                  A 2 Replies Last reply
                                  1
                                  • 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;

                                    A Offline
                                    A Offline
                                    azravian
                                    wrote on last edited by azravian
                                    #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.

                                      A Offline
                                      A Offline
                                      azravian
                                      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 azravian

                                        @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 Online
                                        jsulmJ Online
                                        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

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved