Results 1 to 2 of 2

Thread: Connecting dynamically added properties

  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.

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

    Default Re: Connecting dynamically added properties

    Does anybody believe that the QSignalMapper class could help me with the correct identification and parametrization of the signal?

    I want to ensure that only particular connections are enabled, e.g. "prop3" from "object1" to connect to "prop5" from "object2".

    My current attempt connects ALL props from one object to the other, based on the name. So it also creates connections which I don't want.

    I fear that by creating a separate class for Connections and keeping lists of connections will eventually require me to fully implement a signal/slot system or the observer/listener pattern, while I prefer to use Qt's signal/slot mechanism (as it is probably more robust, more efficient and better documented than what I would create anyway).

    Any hints?

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.