Qt static function Qmetaobject::connectslotsbyname (Qobject * object) automatically connect by naming rules, no manual connect required

Source: Internet
Author: User

See others code see void On_mywidget_slottest ();

Was depressed, did not see his code has connect but can signal and groove can be connected together.

Today's review of the book found the letter of the NB place.

Qmetaobject::connectslotsbyname (Qobject * object) will recursively search for all child objects of the incoming Qt object object, and associate the signals of all matching sub-objects to the object object's slot function that conforms to the following rules void on_< window part name >_< signal name > (< signal parameter >)

If the widget already provides a signal QT can be automatically correlated.

[CPP]View Plaincopyprint?
    1. Statement
    2. Class MyClass
    3. {
    4. Public Slots:
    5. void on_mypushbutton_clicked ();
    6. };
    7. Realize
    8. void Myclass::on_mypushbutton_clicked ()
    9. {
    10. }

This will automatically correlate. I'm ashamed to read.

Reference: http://blog.csdn.net/kfbyj/article/details/8878969

---------------------------------------------------------------------------------

No wonder the UI generated function name is void mainwindow::on_pushbutton_6_clicked () do not need to connect (the name of the button is Pushbutton_6), the original is automatically connected, I was also puzzled and special post asked, And no one has given the answer clearly ...

But here's a question too, what if the signal needs more than one parameter? This connectslotsbyname can only pass one parameter, or do not pass parameters ...

Qt static function Qmetaobject::connectslotsbyname (Qobject * object) automatically connect by naming rules, no manual connect required

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.