Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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 ".
    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()
    {

    }



  • 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);


  • Moderators

    @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



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


  • Lifetime Qt Champion

    @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)
    {
        
    }
    
    


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


  • Moderators

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


  • @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 :(


Log in to reply