Summary of connect and disconnect usage in QT

connect is used to connect signals and slot functions, but we often ignore the last parameter. I encountered a bug when writing code. I selected a symbol for multiple plots. When I select other symbols, the last selected symbol will also be processed. Plotting, the last parameter of connect is mainly a ghost.

When the last parameter of conncet is not written, the slot function will be executed as many times as you connect. The bug I encountered needs to set the last parameter to Qt::UniqueConnection to avoid multiple connections and only connect once.

disconnect() is equivalent to disconnect(this, 0, 0, 0), deletes the association of this signal with any slot

disconnect(slot) is equivalent to disconnect(this, 0, slot, 0), delete the association between this and the slot as the slot

object->disconnect() 即object->disconnect(object->this, 0, 0, 0)

Among them, conncet must be paired with disconnect, otherwise, the signal cannot be connected after disconncet

Guess you like

Origin blog.csdn.net/bureau123/article/details/111726176