This question is an upgrade on the following two questions:
Here is the situation:
MODEL has a pointer to the SERVER (SERVER represents Data) through which it gets the required data and formats them into QStrings
, so that the VIEW can understand them. The model keeps no internal copies of the QList
, it accesses it directly and converts the requ QTcpSocket *
to QStrings
in the QVariant QAbstractItemModel::data
method.
However the list of sockets can change without the Model or View knowing about it if a new connection to the SERVER is established. In that case another QTcpSOcket *
is appended to the SERVERs QList.
How to notify the View on the Model/Data change?
Call
QAbstractItemModel::reset()
from the SERVER on each new connection. I consider this bad for it requires to modify the SERVER for the needs of the MODEL in which case i could of just had the MODEL and the SERVER as a single entity.connect(&server, QTcpServer::newConnection, &model, &StationListModel::reset)
Try to connect the SERVER and MODEL via Signals and Slots. However,&StationListModel::reset
ISN'T a slot, so i believe this isn't the right way.
I would like to hear which of the mentioned approaches (if any) is considered appropriate in the given situation. And is the insisting on MODEL-SERVER loose coupling a bad design choice?