Results 1 to 5 of 5

Thread: hmm..any way to generically link one object to update others that inherit it?

  1. #1
    Join Date
    Nov 2009
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default hmm..any way to generically link one object to update others that inherit it?

    Ok, I'm a bit of a newbie so I'm not sure if this is possible, but if it is its probably going to be a fairly advanced answer, so hence I posted here.

    I've basically got my own object type "arblip", this contains a number of data types. (Stings and doubles mostly).
    I'm also making a set of widgets to display this data in various forms (say, a list that takes arblips and displays selected data from them)

    The arblips themselves are stored in a array.

    Is there any way of creating the widgets &or blip objects in such a way that when a piece of data in one is changed, it will update all the other widgets that use that arblip as a datasource?
    (so, it possibly might involve the arblip object triggering a inherited list of slots when a setter is triggered for it?)

    I can of course do this manually, but as I might end up with quite a few custom widgets it seems nicer if there was a way to organsie my object/data structure for this to be preformed neatly.

    Thanks for any help in advance, and I hope I explained myself clearly enough,

    Thomas

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hmm..any way to generically link one object to update others that inherit it?

    Hi there!

    You make it sound, as if the traditional signal slot mechanism would not be a satisfactory solution for you! But why?

    I describe it anyway: You need to make your arblip a QObject descendant, call the Q_OBJECT macro. Define a signal DataChanged. (Or you may want more granularity and define separate signals for different values that changed.) In each property setter you call "emit DataChanged();" or the respective signal.

    Whenever you "add" an arblip to a displaywidget (this), you just connect those:

    connect(arblip,SIGNAL(DataChanged()),this,Update() );

    There is no problem in connecting the same signal multiple times to different widgets..

    Where exactly is this not what you need or to cumbersome?

    You are speaking of linking to objects that inherit it. Do your displaywidgets inherit your Dataobject??

    HIH

    Johannes
    Last edited by JohannesMunk; 31st January 2010 at 01:34.

  3. #3
    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: hmm..any way to generically link one object to update others that inherit it?

    I think the model-view architecture is perfect for you. You just need to wrap your data in QAbstractItemModel interface (you can use QStandardItemModel or implement your own custom model) and then use one of the standard views or QDataWidgetMapper. If you require filtering or sorting, you can use QSortFilterProxyModel along with all the mentioned classes.
    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.


  4. #4
    Join Date
    Nov 2009
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: hmm..any way to generically link one object to update others that inherit it?

    Thanks for both your suggestions.
    You make it sound, as if the traditional signal slot mechanism would not be a satisfactory solution for you! But why?
    No, it is perfect, I just needed someone to explain how to use it for this purpose...which you did
    I'll probably use the method as you described for now.

    Although wysota suggestion of using a model-view might be better for me in future.

    Thanks for both your help

  5. #5
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hmm..any way to generically link one object to update others that inherit it?

    Ok. Probably you know it, but I missed the SLOT() around the slot in the connect statement :->

    Let me know, if you need more advice!

    Johannes

Similar Threads

  1. How to use the ui_*.h,inherit it or as a member?
    By 75543255 in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2009, 10:45
  2. Replies: 11
    Last Post: 6th March 2009, 22:15
  3. Inherit the QAxWidget
    By MrShahi in forum Qt Programming
    Replies: 3
    Last Post: 29th April 2008, 08:06
  4. immediate update of QT object
    By db in forum Newbie
    Replies: 3
    Last Post: 14th August 2007, 12:25
  5. Object Inherit from QTreeWidgetItem
    By xgoan in forum Qt Programming
    Replies: 6
    Last Post: 18th August 2006, 12: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.