Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Yet another questions about "go to slot" - #1 need an example adding / using signal parameters

    General and Desktop
    5
    8
    237
    Loading More Posts
    • 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.
    • A
      AnneRanch last edited by

      I like to further improve my "connect" skill using "go to slot ".
      Have been trying to find ( asked Mrs Google ) an example of usage of "signal parameters".
      No success so far.

      void on_<object name>_<signal name>(<signal parameters>);

      Anybody can help me ?

      Here is "plain" "go to slot" function created in QDesigner using "go to slot " and selecting "SIGNAL " cliick(). Connecting using GUI to "SLOT " clear() works fine , but it does not show in the "on_(object)_(signal ) function .

      void TabWidget_Chat::on_pushButton_13_clicked()
      {

      }

      J.Hilk CP71 3 Replies Last reply Reply Quote 0
      • S
        stretchthebits last edited by stretchthebits

        You want to know what the function should look like for a button that gets pushed?
        Your on_pushButton_13_clicked() looks fine,
        In your TabWidget_Chat class, put
        private slots:
        void on_pushButton_13_clicked();

        and in your TabWidget_Chat constructor, allocate your button and then call:
        connect(THEBUTTON, &QAbstractButton::clicked, this, &TabWidget_Chat::on_pushButton_13_clicked, Qt::AutoConnection);

        1 Reply Last reply Reply Quote 1
        • J.Hilk
          J.Hilk Moderators @AnneRanch last edited by

          @AnneRanch said in Yet another questions about "go to slot" - #1 need an example adding / using signal parameters:

          I like to further improve my "connect" skill using "go to slot ".

          let me stop you right here.

          If you wan't to improve your "connect" skill than never ever use the connect by name feature -aka go to slot, when using Designer plugin.
          These types of connections are very brittle, as a simple object rename would break your code

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

          Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

          1 Reply Last reply Reply Quote 4
          • A
            AnneRanch last edited by

            BUMP
            ... an example of usage of "signal parameters".
            while using "go to slot :

            void on_<object name>_<signal name>(<signal parameters>);

            Anybody can help me ?

            mrjj J.Hilk 2 Replies Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion @AnneRanch last edited by

              @AnneRanch

              Hi
              I'm not sure I understand what you are after.
              If you use Go to slot with a signal that has a parameter then it's added too.
              Like the Toggle signal that has a bool

              alt text

              gives

              void MainWindow::on_radioButton_3_toggled(bool checked)
              {
                  
              }
              
              
              1 Reply Last reply Reply Quote 4
              • CP71
                CP71 @AnneRanch last edited by

                @AnneRanch
                Hi
                More in general.
                In ui you usually have controls that derive from QWidget then QObject.

                in .h of your UI
                protected slots:
                void MyRadioButton(bool)

                in .cpp of your UI
                So you can connect function to connect a signal of QWidget to your slot. so where you initialize your UI you can write
                connect( ui->MyRadioButton, &QRadioButton::toggled, this, &MyUiObject::MyRadioButton );

                void MyUiObject::MyRadioButton( bool value )
                {
                ...
                }

                Using "go to slot" is easy and fast but you could have a problem if you change the name of a control, you can compile the project but your old slot is no longer connect.

                1 Reply Last reply Reply Quote 1
                • J.Hilk
                  J.Hilk Moderators @AnneRanch last edited by

                  @AnneRanch said in Yet another questions about "go to slot" - #1 need an example adding / using signal parameters:

                  BUMP
                  ... an example of usage of "signal parameters".
                  while using "go to slot :

                  void on_<object name>_<signal name>(<signal parameters>);

                  Anybody can help me ?

                      void on_pushButton_13_toggled(bool checked);
                      void on_pushButton_13_clicked(bool checked);
                  

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

                  Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                  1 Reply Last reply Reply Quote 1
                  • CP71
                    CP71 @AnneRanch last edited by

                    @AnneRanch
                    Only another note
                    When you manually connect a control's signal to your slot don't use the same name of "go to slot" because else your slot will be called twice, once for "go to slot" mechanism and once for your connect.

                    e.g.
                    if you have a push button called on_pushButton_13 you musn't call your slot void on_pushButton_13_clicked(bool checked); if you use the connect function to manage clicked signal.

                    I hope I'm clear, no for you but for my english :(

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post