PDA

View Full Version : How to connect more than one signals



updaterr
3rd July 2014, 22:25
Hi
I have a problem with synchronization several XmlListModel. Sometimes I need to reload one of them. When I reload one of them, I want to reload all of them. After reload is yet to proceed to the next instruction. And here I have a problem. How to check all XmlListModel status, and then pursue further instructions? Is the only solution is to check status each XmlListModel every x seconds ? I would like better solution in QML


function reloadAndWait()
{
if XmlListModel.status=XmlListModel.Ready and XmlListModel2.status=XmlListModel.Ready {..} //if not -> wait to status=ready
return true
else
return false //and drop some error string
}

anda_skoa
4th July 2014, 10:19
Your target state is a combination of model states, which sounds like extactly what property bindings do



readonly property bool allModelsReady: model1.status == XmlListModel.Ready && model2.status == XmlListModel.Ready && ....


Cheers,
_

updaterr
4th July 2014, 13:25
But How implement waiting ?

if(allModelsReady)
{
doSomething();
...
}
else
{
waitToReady
}

anda_skoa
4th July 2014, 15:10
event driven programs usually don't wait, they react on changes.

You could react to the change of the new property



onAllModelsReadyChanged: {
if(allModelReady) {
}
}


But you should also examine if some of the things you want to do can't also be handled declaratively, i.e. depend on the value of allModelsReady directly.

Can you give some examples of what you do when all models have reached the ready state?

Cheers,
_

updaterr
4th July 2014, 16:27
I have two XmlListModel: TitleListModel, CostListModel. Sometimes I use function to reload that, merge data to one ListModel, and do some other stuff. But usually CostListModel had faster status=Ready than TitleListModel. I need:
1. Reload TitleListModel
2. Reload CostListModel
3. Wait to TitleListModel.status=Ready and CostListModel.status=Ready <- I have proble with this
4. When status are ready, do some functions;
5. When status are'nt ready, drop some error strings

anda_skoa
5th July 2014, 12:45
Waiting is implicit, you don't have to do anything.
The properties will change by themselves, you only need to react to the change.

For your point 5 it looks like, additional to the allModelsReady property, you will also want an anyModelError property, something like



readonly property bool anyModelHasError: titleModel.status == XmlListModel.Error | costModel.status == XmlListModel.Error


Cheers,
_