1. 程式人生 > >Qt 訊號連線多個槽函式 執行順序

Qt 訊號連線多個槽函式 執行順序

執行順序   同一訊號連線多個槽呢,槽函式執行沒有絕對的先後順序。如:connect(slider,&QSlider::valueChanged, spin_box,&QSpinBox::setValue);connect(slider,&QSlider::valueChanged, this,&QWidget::showValue);   在Qt5之前,並不是setValue一定會比showValue先執行。   但在Qt5中,文件中這樣介紹:A signal can be connected to many slots and signals. Manysignals can be connected to one slot.If a signal is connected to several slots, the slots areactivated in the same order in which the connections were made,when the signal is emitted.(一個訊號連線多個槽,訊號發射後,會按照連結順序執行)。    經過簡單測試的確如此:
Qt之訊號與槽
Qt之訊號與槽