为什么在编辑完成之前调用returnPressed?我可以重新订购吗?

Why is returnPressed called before editingFinished? Can I reorder it?

我使用 editingFinished 信号来 validate/correct/cache 一些值。当按下按钮时,我希望字段中的值是正确的。

现在为了加快我的工作速度,我连接 returnPressed 以调用按钮按下时调用的内容。我期望的行为是这样的:

但是,我看到连接到returnPressed的插槽实际上是先处理的。

现在,我知道我可以将 returnPressed 连接到另一个首先调用 editingFinished 插槽的插槽,然后执行操作来解决这个问题,但我的问题是,为什么这样的行为?还是订单未指定而恰好是我的订单?如果是前一种情况,我可以更改顺序吗?

why is the behavior like this?

回答这个是猜想,但符合我的预期。 editingFinished 听起来像是最后的决定。

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

好像不是explicitly specified,但是editingFinished的描述在returnPressed之后,可以作为一个暗示。

In the former case, can I change the order?

不更改源代码并重新编译就不行。只需切换连接即可。

顺序来自信号发出的顺序。直接连接的插槽就像普通的函数调用一样工作。通过 Qt 源代码挖掘我能够找到这个:

Here 我们可以看到,QWidgetLineControl 负责 returnPressededitingFinished 信号:

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

并且如 here 所示,acceptededitingFinished 之前发出。

emit accepted();
emit editingFinished();