Results 1 to 3 of 3

Thread: Object Id visibility and best practices

  1. #1
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Default Object Id visibility and best practices

    {QtQuick 2.0, Qt 5.1.0, Mingw}

    If A.qml is a composition in B.qml which is a composition in main.qml then A.qml can see and refer to all object id’s in B.qml as well as main.qml of which it has no idea of if seen in isolation. Is doing so recommended as a good practice in qml world ?

    eg.,

    Qt Code:
    1. //A.qml
    2. Rectangle {
    3. //can see and use objRoot (see main.qml below) and one (see B.qml below)
    4. }
    5.  
    6. //B.qml
    7. Item {
    8. One { //assume there's One.qml too
    9. id: one
    10. }
    11.  
    12. A {
    13. }
    14. }
    15.  
    16. //main.qml
    17. Rectangle {
    18. id: objRoot
    19.  
    20. B {
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 
    An eg. when this could be required: A.qml has a drag-able component. Then when it is dragged we would need to call ParentChange to make objRoot the parent for the duration of the drag so that it remains a top level item, visible no matter where it’s dragged around the window.

    If this is not a good practice (because if later someone decides to give a similar object id in the composition chain then the one that is encountered 1st would be used breaking the code eg., if Someone included a composition of Some.qml in B.qml in addition to A.qml and One.qml above and decides to name its id as objRoot it would be perfectly legal but would silently break the code) then what’s the alternative ?

  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: Object Id visibility and best practices

    If A needs an object to reparent something to then it should have a property for that and the code using it should set the appropriate object as the properties value.

    Cheers,
    _

  3. #3
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Default Re: Object Id visibility and best practices

    If it's deep inside composition-chain you would end up requiring a lot of property aliases all the way up

Similar Threads

  1. Server programming - Best Practices
    By Affenbrotbaum in forum Newbie
    Replies: 15
    Last Post: 19th January 2011, 19:50
  2. Best practices concerning QStandardItemModel
    By tim47 in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2010, 05:29
  3. query about best practices
    By Raajesh in forum Qt Programming
    Replies: 3
    Last Post: 13th June 2008, 18:47
  4. Signals/slots best practices?
    By gfunk in forum Qt Programming
    Replies: 5
    Last Post: 18th August 2007, 18:50
  5. Qt <-> Java - Best Practices?
    By mentat in forum Qt Programming
    Replies: 6
    Last Post: 20th July 2006, 02:32

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.