Results 1 to 2 of 2

Thread: Connecting dynamically added properties

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Location
    Belgium
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Connecting dynamically added properties

    EDITED: shorter example
    -------------------------------
    I know it is possible to dynamically add properties to QObject derived classes.
    Qt Code:
    1. QObject * one = new QObject();
    2. one->setProperty("prop1", QVariant("value1"));
    3. qDebug() << QVariant(one->property("prop1"));
    To copy to clipboard, switch view to plain text mode 
    Suppose I have a second class "two", with a similar property (having the same data type).
    But I was wondering how to connect both properties using signals and slots?

    Should I connect the QObject::setProperty()method? I fear that this would probably mean that setting any property on the first class, would automatically create the same property on the second class, which is clearly not the intention. I only want to ensure that if I connect two properties, setting the first will set the second one automatically.
    I will first try to do this in one direction and worry about recursion later on.

    Edited:
    I created a wrapper method as a slot, "setValue" and a signal "valueChanged", which works, but as a result, if I connect two classes, all properties with the same name get connected. I only want to allow specific connections.
    What I would like to avoid is creating a list of mapped properties (e.g. listener pattern) since I fear that I would create something that resembles the signal and slot mechanism, which is clearly a waste of efforts. I would rather use what is already implemented in Qt.

    I read about "QDynamicPropertyChangeEvent". Is that an approach to it?
    Last edited by stefkeB; 4th December 2008 at 13:10.

Similar Threads

  1. LibQxt
    By jpn in forum Qt-based Software
    Replies: 10
    Last Post: 9th October 2009, 22:20

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