Results 1 to 2 of 2

Thread: Q_PROPERTY and deeply nested custom types

  1. #1
    Join Date
    May 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Exclamation Q_PROPERTY and deeply nested custom types

    Hi
    This is my first post to a Qt forum, and believe me, I'm doing this after some rather serious googling and coding. So, please be gentle, here goes:

    Do you have any non-trivial example of using Q_PROPERTY macros for deeply nested classes. All I can seem to bump into are examples of nested enums or, a one level class that itself is a struct, not a QObject.

    Given classes say, A, B, C, D - all QObjects, all Q_DECLARE_METATYPE declared and registered, all happy with assignment operators, copy constructors and the usual C++ goodness.

    I need (and can't seem to figure out or find a clean example) to do the following.
    class C has a read/write Q_PROPERTY of type B (I tried B*, that didn't work either)
    class B has a read/write Q_PROPERTY of type A
    class D has a read/write of type list of C

    Any help would be deeply appreciated. This is on Qt 4.6 Jan 2010 cut (though same results on 4.7 beta 1). Note, I did find QML examples of the same, just can't use Qml at this point.

    Thanks
    Sammy

  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: Q_PROPERTY and deeply nested custom types

    Let's make one thing clear first. QVariant (which is what Qt property system uses) requires its "members" to be copiable (or to say properly to implement a public copy constructor). QObject doesn't fill this requirement, it's "identity-based" and we operate on it using pointers. So if your A, B, C, D classes inherit QObject somewhere along the line, they can't be put into QVariant (as objects). You can only put pointers to them into QVariant. Trying to go around it will sooner or later result in failure (even if you provide a copy constructor for your object, you still won't be able to copy the QObject sitting below your class).

    So you need to answer two questions first:
    • do I need my objects to inherit QObject?
    • do I need my objects to be values of properties (aka "what benefit do I have from my objects being values of properties")?
    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. Using custom Q_PROPERTY with Stylesheet
    By hubbobubbo in forum Qt Programming
    Replies: 7
    Last Post: 30th September 2010, 10:48
  2. Replies: 4
    Last Post: 5th March 2010, 14:20
  3. Working with QDBus and custom types
    By JuBe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2009, 16:20
  4. QVariant::toString and custom data types
    By Vladimir in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2007, 15:36
  5. QVariant types support for custom properties
    By Dusdan in forum Qt Tools
    Replies: 9
    Last Post: 11th January 2006, 09:55

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.