Results 1 to 3 of 3

Thread: default properties that is not a QDeclarativeListProperty

  1. #1
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: default properties that is not a QDeclarativeListProperty

    Is it possible? All my attempts have failed, specifically:

    Qt Code:
    1. class BSFontLoader
    2. : public QObject
    3. {
    4. Q_OBJECT
    5.  
    6. Q_ENUMS(Status)
    7.  
    8. Q_PROPERTY(QVariantList sources READ sources WRITE setSources)
    9. Q_CLASSINFO("DefaultProperty", "sources")
    10.  
    11. ...
    12. }
    To copy to clipboard, switch view to plain text mode 

    Doing:

    Qt Code:
    1. FontLoader {
    2. "example.ttf"
    3. "bla.ttf"
    4. }
    To copy to clipboard, switch view to plain text mode 

    Does not work.


    Added after 19 minutes:


    I see:

    This marks property as the class's default property. property must be either an object property, or a list property.
    But a QVariantList is neither.
    Last edited by ugluk; 22nd January 2013 at 11:12.

  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: default properties that is not a QDeclarativeListProperty

    Default property is about children in the element tree, so it can be either one object or a list of objects.
    A list of value can already be mapped to the array annotation, e.g.

    Qt Code:
    1. FontLoader {
    2. sources: [ "example.ttf", "bla.ttf" ]
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    ugluk (22nd January 2013)

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

    Default Re: default properties that is not a QDeclarativeListProperty

    I think this might (it's just a guess, I haven't checked it) also work:

    Qt Code:
    1. class BSFontLoader
    2. : public QObject
    3. {
    4. Q_OBJECT
    5.  
    6. Q_ENUMS(Status)
    7.  
    8. Q_PROPERTY(QVariant sources READ sources WRITE setSources) // note -- QVariant, not QVariantList
    9. Q_CLASSINFO("DefaultProperty", "sources")
    10.  
    11. ...
    12. }
    To copy to clipboard, switch view to plain text mode 

    javascript Code:
    1. FontLoader {
    2. id: fl;
    3. [ "example.ttf", "bla.ttf" ]
    4. }
    5.  
    6. FontLoader {
    7. "example.ttf"
    8. }
    To copy to clipboard, switch view to plain text mode 

    setSources() would then need to use QVariant::isList() to check whether one or more values have been set to it. The bad part of all solutions here is that you can't do this:

    javascript Code:
    1. fl.sources.push("xyz")
    To copy to clipboard, switch view to plain text mode 
    or similar (regardless if sources contains an array or not).
    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. What properties can I style for a tab-bar
    By tonnot in forum Qt Programming
    Replies: 8
    Last Post: 13th January 2012, 10:05
  2. Replies: 1
    Last Post: 3rd September 2011, 15:31
  3. about properties
    By jajdoo in forum Newbie
    Replies: 5
    Last Post: 21st July 2011, 14:15
  4. Replies: 0
    Last Post: 18th February 2011, 08:24
  5. dynamic properties
    By Hogwarts in forum Qt Programming
    Replies: 1
    Last Post: 3rd May 2010, 16:37

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
  •  
Qt is a trademark of The Qt Company.