How to observe changes in a list
-
Greetings fellow devs. I'm new to C++ and Qt, and I'm currently working on an app that plays music, which uses the Phonon media API. This app is meant to have a queue of music tracks which are meant to play in order. Tracks can be added and removed to and from that list at any time. The app is also meant to have an area which always displays an up-to-date image of that queue. What I'm struggling with is how to update said area each time the queue changes. The class
Phonon::MediaObjectthat hosts the queue doesn't seem to have any signal which would help me detect changes in the queue at all. Even the type of the queue,QList, doesn't seem to cast a signal when changed. This doesn't seem to leave me any options within theMediaObjectclass, so I'm now a bit lost.. My next attempt would be to implement a new class which inheritsMediaObject, but this would come with a lot of new challenges which I think I would be wise to avoid. Could any of you perhaps tell me how to do this? Or is there another solution that I'm missing? I'd be very thankful for a bit of help.
Documentation for theMediaObjectclass can be found here: https://api.kde.org/phonon/html/classPhonon_1_1MediaObject.html
The code forMediaObjectcan be found here: https://invent.kde.org/libraries/phonon/-/blob/master/phonon/mediaobject.cpp -
Greetings fellow devs. I'm new to C++ and Qt, and I'm currently working on an app that plays music, which uses the Phonon media API. This app is meant to have a queue of music tracks which are meant to play in order. Tracks can be added and removed to and from that list at any time. The app is also meant to have an area which always displays an up-to-date image of that queue. What I'm struggling with is how to update said area each time the queue changes. The class
Phonon::MediaObjectthat hosts the queue doesn't seem to have any signal which would help me detect changes in the queue at all. Even the type of the queue,QList, doesn't seem to cast a signal when changed. This doesn't seem to leave me any options within theMediaObjectclass, so I'm now a bit lost.. My next attempt would be to implement a new class which inheritsMediaObject, but this would come with a lot of new challenges which I think I would be wise to avoid. Could any of you perhaps tell me how to do this? Or is there another solution that I'm missing? I'd be very thankful for a bit of help.
Documentation for theMediaObjectclass can be found here: https://api.kde.org/phonon/html/classPhonon_1_1MediaObject.html
The code forMediaObjectcan be found here: https://invent.kde.org/libraries/phonon/-/blob/master/phonon/mediaobject.cpp@Leonader said in How to observe changes in a list:
My next attempt would be to implement a new class which inherits MediaObject
Why do you want to subclass MediaObject? It is the list of MediaObject which needs to emit a signal if it changes, right? One way would be to implement a class containing QList<MediaObject*> with a well defined interface to alter the list and also all needed signals (like changed()).
Depending on how you're showing this list you should consider using https://doc.qt.io/qt-6/model-view-programming.html -
@Leonader said in How to observe changes in a list:
My next attempt would be to implement a new class which inherits MediaObject
Why do you want to subclass MediaObject? It is the list of MediaObject which needs to emit a signal if it changes, right? One way would be to implement a class containing QList<MediaObject*> with a well defined interface to alter the list and also all needed signals (like changed()).
Depending on how you're showing this list you should consider using https://doc.qt.io/qt-6/model-view-programming.html