0

When entering a QState in QStateMachine a few Widget object properties are set with assignProperty() and the entered() Signal is used to run a Slot method that exec()s a QDialog.

This principally works, but the dialog is created before the properties are assigned, which is not desired, as the properties are only eventally assigned after the dialog is closed.

The exact order were not critical if the dialog would not block (what exactly does it "block"?). The human-perceived appearance should be "simultaneous".

A solution would make the dialog non-blocking or ensure the properties are set prior to the dialog's execution.

I will now try to use a single-shot QTimer to delay the slot that runs the QDialog's exec() but of course I am still looking for a proper solution even if this should work.

4

1 回答 1

0

目前,惯用的解决方案是有两种状态:第一种是设置属性,第二种是显示小部件:

QStateMachine machine;
auto * s1 = QState(&machine);
auto * s2 = QState(&machine);
machine.setInitialState(s1);
s1->assignProperty(widget, "property", value);
...
s1->addTransition(s2);
connect(s2, SIGNAL(entered()), widget, SLOT(exec()));
//or
s2->assignProperty(widget, "visible", true);
machine.start();

请注意,这QDialog::exec()是一个插槽,因此您不需要一个自定义插槽只是exec()一个对话框。将插槽连接到对话框accepted()finished(int)信号以获得结果。

于 2013-10-15T21:04:24.630 回答