2

I use the editingFinished signal to validate/correct/cache some value. When a button is pressed, I then expect the value in the field to be correct.

Now to make my work faster, I connect returnPressed to call what the button press would have called. The behavior I expect is this:

  • editingFinished is emitted, so the application knows the field is edited
  • returnPressed is emitted, to fire off the "form"'s action

However, I see that the slot connected to returnPressed is actually processed first.

Now, I know that I can connect returnPressed to another slot that calls the editingFinished slot first, and then performs the action, to work around this, but my question is, why is the behavior like this? Or is that the order is unspecified and it just happens to be in this order for me? In the former case, can I change the order?

Shahbaz
  • 46,337
  • 19
  • 116
  • 182

2 Answers2

0

why is the behavior like this?

Answering this would be conjecture, but it meets my expectations. editingFinished sounds like the final call.

Or is that the order is unspecified and it just happens to be in this order for me?

It appears to not be explicitly specified, but the fact that the description for editingFinished comes after returnPressed could be taken as a hint.

In the former case, can I change the order?

Not without changing the source code and recompiling. Just switch the connections.

Thomas
  • 4,980
  • 2
  • 15
  • 30
0

The order comes from the order in which the signals are emitted in. A directly connected slot works just like a normal function call. Digging through the Qt source code I was able to find this:

Here we can see, that QWidgetLineControl is in charge of the returnPressed and editingFinished signals:

QObject::connect(control, SIGNAL(accepted()),
    q, SIGNAL(returnPressed()));
QObject::connect(control, SIGNAL(editingFinished()),
    q, SIGNAL(editingFinished()));

And as seen here, accepted is emitted before editingFinished.

emit accepted();
emit editingFinished();
thuga
  • 12,601
  • 42
  • 52