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. Signals and Slots between two classes
Qt 6.11 is out! See what's new in the release blog

Signals and Slots between two classes

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by VRonin
    #2

    Can you use the new connection syntax?
    QObject::connect(&t, SIGNAL(valueChanged(int)),&w, SLOT(setValue(int))); should become QObject::connect(&t,&Test::valueChanged,&w,&Widget::setValue);

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    K 1 Reply Last reply
    2
    • VRoninV VRonin

      Can you use the new connection syntax?
      QObject::connect(&t, SIGNAL(valueChanged(int)),&w, SLOT(setValue(int))); should become QObject::connect(&t,&Test::valueChanged,&w,&Widget::setValue);

      K Offline
      K Offline
      ktrsathish
      wrote on last edited by
      #3

      @VRonin no change. signals are not recieved in slots.

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @ktrsathish said in Singals and Slots between two classes:

        Form::Form(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Form)
        {
        ui->setupUi(this);
        value = 0;
        Test obj;
        }

        What should 'Test obj' do here?

        void Form::on_button_clicked()
        {
        value = 1;
        obj.EnableImage(value);
        }

        This is not the object you're doing your connect on.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        K 1 Reply Last reply
        5
        • Christian EhrlicherC Christian Ehrlicher

          @ktrsathish said in Singals and Slots between two classes:

          Form::Form(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::Form)
          {
          ui->setupUi(this);
          value = 0;
          Test obj;
          }

          What should 'Test obj' do here?

          void Form::on_button_clicked()
          {
          value = 1;
          obj.EnableImage(value);
          }

          This is not the object you're doing your connect on.

          K Offline
          K Offline
          ktrsathish
          wrote on last edited by
          #5

          @Christian-Ehrlicher My actual implementaion shall follow the above architecture. so I have written the sample code to work first.

          mrjjM 1 Reply Last reply
          0
          • K ktrsathish

            @Christian-Ehrlicher My actual implementaion shall follow the above architecture. so I have written the sample code to work first.

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

            @ktrsathish
            Hi
            Could you zip sample and upload via
            https://www.justbeamit.com/ ( single use :( )
            any other dropbox, Google drive, etc that can give a link
            with no registration required to get it.

            Code looks ok, but its easy to miss stuff due to all the scrolling.

            K 1 Reply Last reply
            0
            • mrjjM mrjj

              @ktrsathish
              Hi
              Could you zip sample and upload via
              https://www.justbeamit.com/ ( single use :( )
              any other dropbox, Google drive, etc that can give a link
              with no registration required to get it.

              Code looks ok, but its easy to miss stuff due to all the scrolling.

              K Offline
              K Offline
              ktrsathish
              wrote on last edited by
              #7

              @mrjj https://drive.google.com/file/d/1d0Cc86uItT6F-ZzpbWtreATYICApRG1U/view?ts=5bd73a93
              Please check the code and let me know the details.

              mrjjM 1 Reply Last reply
              0
              • K ktrsathish

                @mrjj https://drive.google.com/file/d/1d0Cc86uItT6F-ZzpbWtreATYICApRG1U/view?ts=5bd73a93
                Please check the code and let me know the details.

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

                @ktrsathish
                super !
                but it asks permissions.
                Can you remove that ?

                K 1 Reply Last reply
                0
                • mrjjM mrjj

                  @ktrsathish
                  super !
                  but it asks permissions.
                  Can you remove that ?

                  K Offline
                  K Offline
                  ktrsathish
                  wrote on last edited by
                  #9

                  @mrjj https://drive.google.com/file/d/1d0Cc86uItT6F-ZzpbWtreATYICApRG1U/view?usp=sharing can you try now.

                  mrjjM 1 Reply Last reply
                  1
                  • K ktrsathish

                    @mrjj https://drive.google.com/file/d/1d0Cc86uItT6F-ZzpbWtreATYICApRG1U/view?usp=sharing can you try now.

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

                    @ktrsathish
                    Hi
                    In class Form, you have
                    private:
                    ..
                    Test obj;

                    and you use that to emit

                    void Form::on_ABS_ON_clicked()
                    {
                    value = 1;
                    obj.EnableImage(value);
                    }

                    BUT
                    the one you hook up in main is another test instance
                    and its not used to emit the signal.

                    Test t;
                     QObject::connect(&t, &Test::ValueChanged, &w, &Widget::setValue);
                    
                    t is not the one u use to emit signal.
                    
                    

                    So that is why all looks fine but nothing happens.
                    The actual emitter object is not connected up.

                    So it was as mr. @Christian-Ehrlicher said / suggested

                    K 1 Reply Last reply
                    5
                    • mrjjM mrjj

                      @ktrsathish
                      Hi
                      In class Form, you have
                      private:
                      ..
                      Test obj;

                      and you use that to emit

                      void Form::on_ABS_ON_clicked()
                      {
                      value = 1;
                      obj.EnableImage(value);
                      }

                      BUT
                      the one you hook up in main is another test instance
                      and its not used to emit the signal.

                      Test t;
                       QObject::connect(&t, &Test::ValueChanged, &w, &Widget::setValue);
                      
                      t is not the one u use to emit signal.
                      
                      

                      So that is why all looks fine but nothing happens.
                      The actual emitter object is not connected up.

                      So it was as mr. @Christian-Ehrlicher said / suggested

                      K Offline
                      K Offline
                      ktrsathish
                      wrote on last edited by
                      #11

                      @mrjj said in Signals and Slots between two classes:

                      Test t;
                      QObject::connect(&t, &Test::ValueChanged, &w, &Widget::setValue);

                      Thanks. It is solved.

                      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