Results 1 to 10 of 10

Thread: Eliminate Binding loop warning

  1. #1
    Join Date
    Dec 2010
    Location
    Veszprém, Hungary
    Posts
    34
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Eliminate Binding loop warning

    Hello,

    I have a sample code listed below. It works well, but always writes a debug message:
    QML QDeclarativeRectangle_QML_0: Binding loop detected for property "parent"

    Do anybode have any idea, how could I eliminate this warning?

    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. id: rect1
    5. color: "lightblue"
    6. width: 800
    7. height: 600
    8.  
    9. Item {
    10. width: 600
    11. height: 600
    12.  
    13. Rectangle {
    14. id: test
    15. parent: getRootObject()
    16. anchors.fill: parent
    17. color: "yellow"
    18. opacity: 0.5
    19.  
    20. //! goes to the root object via the item's parent property
    21. function getRootObject() {
    22. var item = test.parent
    23. while (item.parent != undefined) {
    24. item = item.parent
    25. //console.log("w: "+ item.width + " h: " + item.height)
    26. }
    27. return item
    28. }
    29. }
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

  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: Eliminate Binding loop warning

    What's the point of what you are trying to do? Why not simply declare the object with a proper parent in the first place?
    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. #3
    Join Date
    Dec 2010
    Location
    Veszprém, Hungary
    Posts
    34
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Eliminate Binding loop warning

    It's a MessageBox component. I have to fill the screen with a MouseArea to 'eat' the mouse click events.
    There is a controller logic in QML which loads different QML files. But I want an universal messagebox, and not always really know, 'who' is the root object, that's why I wanted to use this approach.
    Maybe I can solve simply returning from the C++ side a pointer of the rootObject, but I wanted to keep it in the QML side.

  4. #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: Eliminate Binding loop warning

    You can keep it in QML. Create the component on the fly when you need it and just put it on top of everything, you don't need to reparent it.
    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.


  5. #5
    Join Date
    Dec 2010
    Location
    Veszprém, Hungary
    Posts
    34
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Eliminate Binding loop warning

    Do You have a sample how do you think? If I not reparent the item, then positioning will be strange. For example I have an info and a task bar at the upper and the lower parts of the screen. If I don't reparent the item and set x and y to 200, it will be relative to the parent item - the upper side of the screen or the lower. Or not?

  6. #6
    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: Eliminate Binding loop warning

    If you create the item parentless, it will be working in scene (aka absolute) coordinates. Or you can declare it as a child of your root element and work in this element's coordinates.

    However wouldn't it be simpler to make your message box modal simply by disabling all other mouse areas? You can do that with one property binding.
    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.


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

    laszlo.gosztola (17th August 2011)

  8. #7
    Join Date
    Dec 2010
    Location
    Veszprém, Hungary
    Posts
    34
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Eliminate Binding loop warning

    Maybe disabling the Mouse Areas is possible but I also use a dimmer component to fade a bit out the background.
    So, if I create the MessageBox without parent as You said, get the root item with my getRootItem function I can set the Dimmer's width and height to it's height and width, and it's tha same than the original problem.
    I try it...


    Added after 10 minutes:


    Not perfect. In the sample I wrote in the first post, works well.
    But in the real code not OK.

    Maybe the problem is that I don't create the component on the fly, and it get a parent.
    I have something like this:
    InfoBar.qml
    Qt Code:
    1. import QtQuick 1.0
    2. Item {
    3. id: container
    4. ....
    5. Button {
    6. onClicked: errorMessage.show()
    7. }
    8.  
    9. MessageBox {
    10. id: errorMessage
    11. ...
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    I removed the parent property from the MessageBox, but it stayed relative to the item
    Last edited by laszlo.gosztola; 17th August 2011 at 22:08.

  9. #8
    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: Eliminate Binding loop warning

    Quote Originally Posted by laszlo.gosztola View Post
    I removed the parent property from the MessageBox, but it stayed relative to the item
    QML is a declarative language. If you declare one item within the scope of another, it will be its child.

    I don't know why you're so reluctant to create the element just when you need it. Especially that you're trying to use it in imperative manner anyway.


    Added after 23 minutes:


    Here is a crude but working example of a completely declarative way of approaching the problem:

    javascript Code:
    1. import QtQuick 1.0
    2.  
    3.  
    4.  
    5. Rectangle {
    6. id: rectangle1
    7. width: 360
    8. height: 360
    9.  
    10. function showBox() {
    11. messagebox.state = "shown"
    12. }
    13.  
    14. Rectangle {
    15. // some button
    16.  
    17. width: 100
    18. height: 50
    19. color: 'red'
    20. anchors.left: parent.left
    21. anchors.leftMargin: 5
    22. anchors.top: parent.top
    23. anchors.topMargin: 5
    24. MouseArea {
    25. anchors.fill: parent
    26. onClicked: showBox()
    27. }
    28. }
    29.  
    30. Rectangle {
    31. id: messagebox
    32. anchors.fill: parent
    33. color: '#dd000000'
    34. opacity: 0
    35. z: 1000
    36. Rectangle { // box
    37. width: 200
    38. height: 100
    39. radius: 10
    40. anchors.centerIn: parent
    41. color: 'white'
    42.  
    43. Rectangle {
    44. width: 50
    45. height: 30
    46. radius: 3
    47. border.color: "#000055"
    48. border.width: 1
    49. color: "#5555FF"
    50. anchors.centerIn: parent
    51.  
    52. Text {
    53. text: 'OK'
    54. anchors.centerIn: parent
    55. color: "white"
    56. }
    57. MouseArea {
    58. anchors.fill: parent
    59. onClicked: messagebox.state = 'hidden'
    60. }
    61. }
    62.  
    63. }
    64. states: [
    65. State {
    66. name: "hidden"
    67. PropertyChanges { target: messagebox; opacity: 0 }
    68. },
    69. State {
    70. name: "shown"
    71. PropertyChanges { target: messagebox; opacity: 1 }
    72. }
    73.  
    74. ]
    75. transitions: [
    76. Transition {
    77. NumberAnimation { properties: "opacity"; duration: 500 }
    78. }
    79. ]
    80. }
    81. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 17th August 2011 at 23:10.
    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.


  10. #9
    Join Date
    Dec 2010
    Location
    Veszprém, Hungary
    Posts
    34
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Eliminate Binding loop warning

    Hello,
    thanks for your efforts to solve this problem.
    The background why I try this way: This MessageBox component works well in a former project. Exactly, there is a universal dialog component and a MessageBox component which is 'inherited' from the Dialog (I don't know how you say it in declarative world). Each of them is creatable from the C++ logic also. The MessageBoxes are created at initiialisation, just like in your example and if e.g. an error occurs, I call the show() method. But, in that project I know always the root object, and can set the parent.
    Qt Code:
    1. MessageBox {
    2. id: errorMsgBox
    3.  
    4. parent: root
    5. type: MessageBoxType.Critical
    6. title: "Saving Failed"
    7. message: "Wrong input"
    8.  
    9. Component.onCompleted: {
    10. addButton(0, "OK")
    11. }
    12. onButtonClicked: {
    13. errorMsgBox.hide()
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    In this case root is the 'base' object, which fills the whole screen. It works well.

    But in this project, there concept is that there are different tasks, which has different screens. A 'screen_controller' manages task and screen changes. And if I try to use the base object like I done in the previsous sample, it says that the variable not found. (Maybe I should take a deeper look why the debugger says it.) But this was the reason why I wanted to find the root object with this function. I also think that it's better to declare the objects like you do in your last example, but I need the fill the whole screen.

    So far, I think the possibilities are the following:
    - create the MessageBox on the fly, when I need it, and set the width and height to the root Object's width and height. Not elegant and maybe slows down the app, when I create the component
    - create the component in the QML file, like you did - if I know the root object, everything is fine - if the engine don't find the root object, then I should find with my function and reparent it (works, but gives the warning). Maybe finding the root object, use the width and height of it, and set the coordinates with some hack of mapToGlobal functions to set the x and y properties, etc.
    - or get a pointer to the root object from the c++ side. Not elegant, too.

  11. #10
    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: Eliminate Binding loop warning

    I'm sorry, I still fail to see why you don't know what the root object is and why you want to reparent the box to the root object. In my opinion it is the responsibility of the message box object to know where to place itself. The way I see it, you are trying to employ an imperative (do this, then do this, then do this) approach in a declarative (I want it to be doing this and this) environment. If you want to know the root object, then just add an identifier for it and then refer to this identifier.
    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.


Similar Threads

  1. Replies: 10
    Last Post: 15th August 2011, 19:33
  2. Replies: 4
    Last Post: 6th August 2011, 02:40
  3. Replies: 5
    Last Post: 16th February 2011, 09:33
  4. Resizing QTableView to eliminate horizontal scroll bar?
    By russford in forum Qt Programming
    Replies: 7
    Last Post: 18th March 2010, 08:21
  5. Replies: 5
    Last Post: 19th April 2009, 14:24

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.