Results 1 to 6 of 6

Thread: How to connect more than one signals

  1. #1
    Join Date
    Apr 2014
    Location
    PÅ‚ock, Poland
    Posts
    13
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default How to connect more than one signals

    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

    Qt Code:
    1. function reloadAndWait()
    2. {
    3. if XmlListModel.status=XmlListModel.Ready and XmlListModel2.status=XmlListModel.Ready {..} //if not -> wait to status=ready
    4. return true
    5. else
    6. return false //and drop some error string
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to connect more than one signals

    Your target state is a combination of model states, which sounds like extactly what property bindings do

    Qt Code:
    1. readonly property bool allModelsReady: model1.status == XmlListModel.Ready && model2.status == XmlListModel.Ready && ....
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Apr 2014
    Location
    PÅ‚ock, Poland
    Posts
    13
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to connect more than one signals

    But How implement waiting ?
    Qt Code:
    1. if(allModelsReady)
    2. {
    3. doSomething();
    4. ...
    5. }
    6. else
    7. {
    8. waitToReady
    9. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by updaterr; 4th July 2014 at 13:31.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to connect more than one signals

    event driven programs usually don't wait, they react on changes.

    You could react to the change of the new property

    Qt Code:
    1. onAllModelsReadyChanged: {
    2. if(allModelReady) {
    3. }
    4. }
    To copy to clipboard, switch view to plain text mode 

    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,
    _

  5. #5
    Join Date
    Apr 2014
    Location
    PÅ‚ock, Poland
    Posts
    13
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to connect more than one signals

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to connect more than one signals

    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

    Qt Code:
    1. readonly property bool anyModelHasError: titleModel.status == XmlListModel.Error | costModel.status == XmlListModel.Error
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    updaterr (5th July 2014)

Similar Threads

  1. Difficult connect of signals and slots
    By Ozzy in forum Qt Programming
    Replies: 13
    Last Post: 5th February 2014, 07:38
  2. Replies: 2
    Last Post: 18th April 2013, 13:15
  3. Replies: 1
    Last Post: 28th October 2011, 11:40
  4. Replies: 16
    Last Post: 16th February 2010, 14:17
  5. how to connect events with signals in QGraphicsScene?
    By nataly in forum Qt Programming
    Replies: 0
    Last Post: 3rd November 2009, 16:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.