10

I'm looking for general-purpose container/collection classes (e.g., lists, maps) that emit Qt signals when items are added or removed.

I know the standard Qt container classes don't do it. Anyone know of any OSS library that has observable containers?

I realize there are issues with templates and Qt features. If it were easy, I'd just do it myself instead of looking for an existing one. :)

Thanks.

Chris
  • 4,734
  • 2
  • 19
  • 26

1 Answers1

2

But it is easy :) Just don't try subclassing the container class. Create a QObject subclass that contains an instance of the container you want to use and write Add and Remove methods that emit the signals you want when they are called.

Arnold Spence
  • 21,942
  • 7
  • 74
  • 67
  • 1
    Ok, that's true as far as it goes. I guess I wasn't specific enough. What I was really hoping for is a more "complete" solution that includes features like iterators, insertion into the middle, etc. I could write my own wrapper around another container class, but I'd rather not have to write wrappers around every method I wanted to expose. But if I don't find a better approach that's probably what I'll do. – Chris Jul 14 '11 at 18:29
  • As @Chris pointed out, this answer overlooks the lost benefits of Qt's container classes - iterators, foreach looping, etc. – walkingTarget Apr 07 '17 at 20:59