Search code examples
qtsignals-slots

How to know which signal is emitted first?


For example, in a QTableWidget when I click on a table cell, both cellClicked() and itemSelectionChanged() will be emitted. But which one comes first? Is it predetermined or not?

So basically the question is, when multiple signals can be emitted by a single operation, which one comes first? I didn't find any documentation on this.


Solution

  • You can connect to both signals and see which slot is called first. itemSelectionChanged is the first.

    You are correct: this behavior is not documented.

    When multiple signals are emitted by the same operation, and the order is not clearly specified, it is better not to rely on it:

    • It might change in the next version of Qt
    • In some rare cases it might even change while the application is running (when queued connections are used internally)