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. help on signals and slots

help on signals and slots

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 628 Views
  • 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.
  • R Offline
    R Offline
    russjohn834
    wrote on last edited by
    #1

    Hello,

    I'm new to QT and signals and slots mechanism, correct me where I'm wrong?

    I have a label in a form, the text need to be changed upon clicking a button , I trying to implement using a signals and slots.
    My signal will be emitted as follows:

    void MainOne::on_pushButton_help_clicked()
    {
        emit textToChange("text updated");
    }
    

    I then connected it as follows:

    connect(this, SIGNAL(textTochange(QString)), this->ui->label_pid, SLOT(setText(QString)));
    

    But this is not working, any help?

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • R russjohn834

      Hello,

      I'm new to QT and signals and slots mechanism, correct me where I'm wrong?

      I have a label in a form, the text need to be changed upon clicking a button , I trying to implement using a signals and slots.
      My signal will be emitted as follows:

      void MainOne::on_pushButton_help_clicked()
      {
          emit textToChange("text updated");
      }
      

      I then connected it as follows:

      connect(this, SIGNAL(textTochange(QString)), this->ui->label_pid, SLOT(setText(QString)));
      

      But this is not working, any help?

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

      @russjohn834 Did you verify that on_pushButton_help_clicked() was executed?
      Do you see any warnings in the application output when executing your app?

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

      1 Reply Last reply
      1
      • R Offline
        R Offline
        russjohn834
        wrote on last edited by
        #3

        @jsulm Thank you. Yes , on_pushButton_help_clicked() is executed. No warnings related to this.

        KroMignonK 1 Reply Last reply
        0
        • R russjohn834

          Hello,

          I'm new to QT and signals and slots mechanism, correct me where I'm wrong?

          I have a label in a form, the text need to be changed upon clicking a button , I trying to implement using a signals and slots.
          My signal will be emitted as follows:

          void MainOne::on_pushButton_help_clicked()
          {
              emit textToChange("text updated");
          }
          

          I then connected it as follows:

          connect(this, SIGNAL(textTochange(QString)), this->ui->label_pid, SLOT(setText(QString)));
          

          But this is not working, any help?

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @russjohn834 said in help on signals and slots:

          connect(this, SIGNAL(textTochange(QString)), this->ui->label_pid, SLOT(setText(QString)));

          is this copy and pasted ? because that is not the signal you emit

          textTochange != textToChange


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          R 1 Reply Last reply
          5
          • R russjohn834

            @jsulm Thank you. Yes , on_pushButton_help_clicked() is executed. No warnings related to this.

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #5

            @russjohn834 said in help on signals and slots:

            Yes , on_pushButton_help_clicked() is executed. No warnings related to this.

            But is the connect() statement executed without warning?

            auto cnxState = connect(this, SIGNAL(textTochange(QString)), this->ui->label_pid, SLOT(setText(QString)));
            
            if(!cnxState)
                qDebug() << "Failed to connect!!!";
            

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply
            1
            • J.HilkJ J.Hilk

              @russjohn834 said in help on signals and slots:

              connect(this, SIGNAL(textTochange(QString)), this->ui->label_pid, SLOT(setText(QString)));

              is this copy and pasted ? because that is not the signal you emit

              textTochange != textToChange

              R Offline
              R Offline
              russjohn834
              wrote on last edited by
              #6

              @J-Hilk Thank you that was the mistake!! But qt did not warn me that it is an undefined signal!! why!?

              J.HilkJ jsulmJ 2 Replies Last reply
              0
              • R russjohn834

                @J-Hilk Thank you that was the mistake!! But qt did not warn me that it is an undefined signal!! why!?

                J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @russjohn834 as you're using the old (Qt4) syntax, you only get a run time warning, not a compile time one


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                2
                • R russjohn834

                  @J-Hilk Thank you that was the mistake!! But qt did not warn me that it is an undefined signal!! why!?

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

                  @russjohn834 said in help on signals and slots:

                  But qt did not warn me that it is an undefined signal!! why!?

                  With this old connect syntax you will not get any warning/error when compiling, only when running your app - that's why I asked you whether you see anything in the application output (in the console). I'm sure there was something.

                  It is better to use new connect syntax: https://wiki.qt.io/New_Signal_Slot_Syntax

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

                  1 Reply Last reply
                  3
                  • R Offline
                    R Offline
                    russjohn834
                    wrote on last edited by
                    #9

                    Thanks a lot for the feedback guys!
                    can someone show me how can I switch this to new connect syntax?

                    connect(this, SIGNAL(textToChange(QString)), this->ui->label_pid, SLOT(setText(QString)));
                    
                    J.HilkJ 1 Reply Last reply
                    0
                    • R russjohn834

                      Thanks a lot for the feedback guys!
                      can someone show me how can I switch this to new connect syntax?

                      connect(this, SIGNAL(textToChange(QString)), this->ui->label_pid, SLOT(setText(QString)));
                      
                      J.HilkJ Online
                      J.HilkJ Online
                      J.Hilk
                      Moderators
                      wrote on last edited by J.Hilk
                      #10

                      @russjohn834
                      sure, but all information needed should actually be inside the wiki page @jsulm linked you

                      connect(this, &MainOne::textToChange, ui->label_pid, &QLabel::setText);
                      

                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      2

                      • Login

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