I'm trying to understand what should the relationships between the Model and the Data be.
For my current situation i have a QTcpServer which keeps a list of active sockets.
class TftpServer : public QTcpServer
{
Q_OBJECT
public:
TftpServer(QObject *parent = 0)
:QTcpServer(parent) {}
QList<QTcpSocket *> m_activeSockets;
The Data that the Model should represent to the View is QList<QTcpSocket *> m_activeSockets;
I feel like the right way to do it is to prevent the duplication of data at any cost for that can lead to inconsistency. Meaning that at all times View should represent the real state Data.
I have tried some approaches, didn't succeeded in any because i have limited time i can spend testing each approach.
Approaches:
1.
TftpServer::m_activeSockets
private, Model accesses it through getters and setters.
- Flaw: How to call methods from the
TftpServer::m_activeSockets
within the Model?
2.
Model friend class of TftpServer
. Directly accesses TftpServer::m_activeSockets
.
- Failed to implement.
3.
TftpServer::m_activeSockets
public. Model has a public reference
QList<QTcpSocket *> & m_activeSockets;
to TftpServer::m_activeSockets
.
- Flaw: Sensitive data publicly available
I would like to find out an optimal solution (feel free to suggest) is considered optimal.
And hear if their are pros of not insisting on a single Data source (in which case the model would just have a copy of TftpServer::m_activeSockets
as its parameter and sync with it on changes).