Results 1 to 4 of 4

Thread: How do I use Q_PROPERTY to get data from my member variables

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How do I use Q_PROPERTY to get data from my member variables

    hi there. I have included Q_PROPERTY in my class and it works fine but I don't know how to retrieve member variable data using Q_PROPERTY instead of getters.
    this is how the property looks like
    Qt Code:
    1. Q_PROPERTY(QString client_name READ getClientName);
    To copy to clipboard, switch view to plain text mode 
    I want to use reflective programming to get the client's name. HOW CAN I DO THIS?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I use Q_PROPERTY to get data from my member variables

    Qt Code:
    1. Q_PROPERTY(QString client_name MEMBER client_name_member_variable)
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I use Q_PROPERTY to get data from my member variables

    Will this give me the actual QString value contained in the variable client_name? and how do I call it from a function without using getters?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I use Q_PROPERTY to get data from my member variables

    The name after the type, in this case client_name, is the name of the property.
    The name after MEMBER is the name of the variable.
    They can of course be the same.

    In a script context, e.g. QML, JavaScript, etc. you can access the property with the name
    Qt Code:
    1. myObject.client_name
    To copy to clipboard, switch view to plain text mode 

    In a C++ context you can access this form or getter-less property using the base property function
    Qt Code:
    1. QString name = myObject->property("client_name").toString();
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 2nd November 2013, 02:10
  2. accessing static member variables of one class in another class
    By jasonknight in forum General Programming
    Replies: 5
    Last Post: 6th September 2010, 14:53
  3. QDevelop debuggng - viewing class member variables
    By dbrmik in forum Qt-based Software
    Replies: 0
    Last Post: 7th January 2009, 10:40
  4. Replies: 5
    Last Post: 18th December 2007, 11:39
  5. QGLWidget doesn't paint when I add another data member
    By Thoughtjacked in forum Qt Programming
    Replies: 6
    Last Post: 17th October 2007, 15:45

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.