Results 1 to 3 of 3

Thread: [SOLVED] How to find out about "read only properties"

  1. #1
    Join Date
    Aug 2006
    Location
    Zürich, Switzerland
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [SOLVED] How to find out about "read only properties"

    I try to populate a QObject descendant with the properties of another QObject descendant to have them identical (for example set a QTreeView to have the same property values as another QTreeView). Retrieving all properties poses no problems:

    Qt Code:
    1. QStringList properties;
    2.  
    3. for(int i = 0; i < myTreeView->propertyCount(); ++i)
    4. properties << QString::fromLatin1(myTreeView->property(i).name());
    To copy to clipboard, switch view to plain text mode 

    When applying the properties to another object I do verify that a property exists like this:

    Qt Code:
    1. const QMetaObject* moOtherTreeView = otherTreeView->metaObject();
    2.  
    3. ...
    4.  
    5. QByteArray propName = properties[ix].toLatin1();
    6.  
    7. // Make sure prop exists
    8.  
    9. if (moOtherTreeView->indexOfProperty(propName) < 0)
    10. continue; // ignore this property
    11.  
    12. ...
    13.  
    14. // Ok, apply property
    15.  
    16. otherTreeView->setProperty(propName, myTreeView->property(propName));
    To copy to clipboard, switch view to plain text mode 

    But unfortunately some of the properties are read only, which is reported by Qt in the debug output:

    Qt Code:
    1. ...
    2.  
    3. updatesEnabled
    4. visible
    5. minimized
    6. QTreeView::setProperty: Property "minimized" invalid, read-only or does not exist
    7. maximized
    8. QTreeView::setProperty: Property "maximized" invalid, read-only or does not exist
    9. fullScreen
    10. QTreeView::setProperty: Property "fullScreen" invalid, read-only or does not exist
    11. sizeHint
    12.  
    13. ...
    To copy to clipboard, switch view to plain text mode 

    My question now is how to find out whether a property is read only or not?

    thanks for any reply!
    Ernst
    Last edited by 3dch; 11th June 2009 at 20:39.

  2. #2
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: How to find out about "read only properties"

    Try checkout return value
    bool QObject::setProperty ( const char * name, const QVariant & value )

    or

    Qt Code:
    1. QMetaProperty QMetaObject::property ( int index ) const
    2. bool QMetaProperty::isWritable () const
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2006
    Location
    Zürich, Switzerland
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find out about "read only properties"

    Thank you, SABROG

    The isWritable() method perfectly solves my problem (next time I should have a deeper look at the Qt docs).

    Regards
    Ernst

Similar Threads

  1. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  2. GCC can't find QSqlDatabase!!
    By brevleq in forum Qt Programming
    Replies: 5
    Last Post: 29th October 2007, 07:05
  3. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  4. QT string Find problem
    By kingslee in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2006, 20:45
  5. Replies: 7
    Last Post: 1st August 2006, 21:15

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.