Results 1 to 4 of 4

Thread: Spurious "Binding loop detected" warnings [solved]

  1. #1
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Spurious "Binding loop detected" warnings [solved]

    I have a qml item that presents a stimulus (image and sound) on the screen on a timer.
    So I have a stimulus state as such:
    Qt Code:
    1. State {
    2. name: "stimulus"
    3. extend: "running"
    4. PropertyChanges {
    5. target: getStimulus()
    6. explicit: true
    7. present: true
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    This state is entered when a timer fires. The getStimulus() function returns the stimulus item that I would like to present. It looks like this:
    Qt Code:
    1. function getStimulus() {
    2. console.log("GetStimulus() currIndex: "+currIndex+" value: "+sequence[currIndex])
    3. var stimIndex = 0
    4. if(sequence[currIndex] === 0) {// non-target
    5. stimIndex = 1+Math.floor(Math.random()*(stimuli.children.length-1))
    6. }
    7. return stimuli.children[stimIndex]
    8. }
    To copy to clipboard, switch view to plain text mode 

    As you can see, when the sequence of stimuli specifies a distractor stimulus, the function chooses a random one amongst the children of an Item that holds them.

    This works perfectly with no warnings.

    However now I want to prevent the same distractor stimulus being shown twice in a row. So I did this:

    Qt Code:
    1. function getStimulus() {
    2. console.log("GetStimulus() currIndex: "+currIndex+" value: "+sequence[currIndex])
    3. var stimIndex = 0
    4. if(sequence[currIndex] === 0) {// non-target
    5. do { // FIXME this prints out spurious "Binding loop detected" warnings. Could rewrite by picking the index out of an array and removing the previous one.
    6. stimIndex = 1+Math.floor(Math.random()*(stimuli.children.length-1))
    7. } while (stimIndex === lastStimIndex);
    8. lastStimIndex = stimIndex
    9. }
    10. return stimuli.children[stimIndex]
    11. }
    To copy to clipboard, switch view to plain text mode 

    This works exactly as I want it to, however on the console it prints out: QML PropertyChanges: Binding loop detected for property "target"
    Not really a functionality problem, but this is very annoying. How do I avoid this warning? There is no actual binding loop here, there just happens to be a loop in the function to find the target.

    Oddly enough, when I rewrote the function with an alternate method based on selecting the index out of an array, the binding loop warning is still there.
    Last edited by pherthyl; 24th May 2013 at 23:16.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Spurious "Binding loop detected" warnings

    "target: getStimulus()" is a binding, not an assignment, thus whenever the value of this function changes, target gets updated. I cannot say what exactly happens in your particular case (most likely because QML detects that stimIndex has influence on the return value of the function) but you can most probably solve it by assigning a value to target manually instead of binding it to a function (e.g. when transiting out of the state you can execute a function that will calculate the new value and assign it to target of the PropertyChanges element.

    Another solution would be to simply shuffle the array of candidates and increase the index in the array until you reach the end of it and then simply shuffle the array again and start from the beginning.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    pherthyl (24th May 2013)

  4. #3
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Spurious "Binding loop detected" warnings

    Thanks. I initially had a property called currentStimulus as the fixed target, and then assigned it in another state, but the code seemed a bit confusing/not as direct.
    You say I could execute a function when transitioning out of that state.. Is there a way to associate a script on state exit, or would it be a StateChangeScript for the following state?


    Added after 19 minutes:


    Solved by pre-calculating the random sequence in C++ and just reading it back out of an array.

    Qt Code:
    1. function getStimulus() {
    2. return stimuli.children[sequence[currIndex]]
    3. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by pherthyl; 24th May 2013 at 23:16.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Spurious "Binding loop detected" warnings

    Quote Originally Posted by pherthyl View Post
    Is there a way to associate a script on state exit, or would it be a StateChangeScript for the following state?
    javascript Code:
    1. transitions: Transition { from: "stimulus"; ScriptAction { script: doSomething(); }}
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    pherthyl (27th May 2013)

Similar Threads

  1. Replies: 3
    Last Post: 29th April 2010, 19:11
  2. Replies: 3
    Last Post: 15th February 2010, 17:27
  3. "Warnings" with NMake and MSVC2008
    By vbman213 in forum Newbie
    Replies: 6
    Last Post: 14th February 2010, 00:44
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.