Fix bug that causes random crashes.
This commit is contained in:
@@ -29,10 +29,7 @@ void Controller::login(QString home, QString user, QString pass) {
|
||||
}
|
||||
|
||||
void Controller::setConnection(QMatrixClient::Connection* conn) {
|
||||
qDebug() << "Setting controller connection.";
|
||||
m_connection = conn;
|
||||
roomListModel = new RoomListModel(m_connection);
|
||||
emit roomListModelChanged();
|
||||
connect(m_connection, &QMatrixClient::Connection::connected, this, &Controller::connected);
|
||||
connect(m_connection, &QMatrixClient::Connection::resolveError, this, &Controller::reconnect);
|
||||
connect(m_connection, &QMatrixClient::Connection::syncError, this, &Controller::reconnect);
|
||||
|
||||
@@ -14,7 +14,6 @@ class Controller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(RoomListModel *roomListModel READ getRoomListModel NOTIFY roomListModelChanged)
|
||||
Q_PROPERTY(QMatrixClient::Connection *connection READ getConnection WRITE setConnection NOTIFY connectionChanged)
|
||||
Q_PROPERTY(bool isLogin READ getIsLogin WRITE setIsLogin NOTIFY isLoginChanged)
|
||||
Q_PROPERTY(QString userID READ getUserID WRITE setUserID NOTIFY userIDChanged)
|
||||
@@ -31,9 +30,6 @@ public:
|
||||
// All the non-Q_INVOKABLE functions.
|
||||
|
||||
// All the Q_PROPERTYs.
|
||||
RoomListModel* roomListModel;
|
||||
RoomListModel* getRoomListModel() { return roomListModel; }
|
||||
|
||||
QMatrixClient::Connection* m_connection;
|
||||
QMatrixClient::Connection* getConnection() { return m_connection; }
|
||||
void setConnection(QMatrixClient::Connection* conn);
|
||||
@@ -71,7 +67,6 @@ private:
|
||||
void reconnect();
|
||||
|
||||
signals:
|
||||
void roomListModelChanged();
|
||||
void connectionChanged();
|
||||
void isLoginChanged();
|
||||
void userIDChanged();
|
||||
|
||||
@@ -5,7 +5,16 @@
|
||||
|
||||
#include "controller.h"
|
||||
|
||||
RoomListModel::RoomListModel(QMatrixClient::Connection* m_connection) : m_connection(m_connection) {
|
||||
RoomListModel::RoomListModel() {
|
||||
|
||||
}
|
||||
|
||||
RoomListModel::~RoomListModel() {
|
||||
|
||||
}
|
||||
|
||||
void RoomListModel::setConnection(QMatrixClient::Connection *conn) {
|
||||
m_connection = conn;
|
||||
beginResetModel();
|
||||
m_rooms.clear();
|
||||
connect(m_connection, &QMatrixClient::Connection::newRoom, this, &RoomListModel::addRoom);
|
||||
@@ -16,10 +25,6 @@ RoomListModel::RoomListModel(QMatrixClient::Connection* m_connection) : m_connec
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
RoomListModel::~RoomListModel() {
|
||||
|
||||
}
|
||||
|
||||
QMatrixClient::Room* RoomListModel::roomAt(int row) {
|
||||
return m_rooms.at(row);
|
||||
}
|
||||
|
||||
@@ -16,14 +16,20 @@ class RoomListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QMatrixClient::Connection *connection READ getConnection WRITE setConnection NOTIFY connectionChanged)
|
||||
|
||||
public:
|
||||
explicit RoomListModel(QMatrixClient::Connection* m_connection = 0);
|
||||
explicit RoomListModel();
|
||||
~RoomListModel();
|
||||
|
||||
enum RoomModelRoles {
|
||||
NameRole, ValueRole, AvatarRole
|
||||
};
|
||||
|
||||
QMatrixClient::Connection* m_connection;
|
||||
QMatrixClient::Connection* getConnection() { return m_connection; }
|
||||
void setConnection(QMatrixClient::Connection* conn);
|
||||
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
|
||||
Q_INVOKABLE QMatrixClient::Room* roomAt(int row);
|
||||
@@ -32,6 +38,7 @@ public:
|
||||
Q_INVOKABLE int rowCount(const QModelIndex& parent=QModelIndex()) const override;
|
||||
|
||||
signals:
|
||||
void connectionChanged();
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -41,7 +48,6 @@ private slots:
|
||||
void addRoom(QMatrixClient::Room* room);
|
||||
|
||||
private:
|
||||
QMatrixClient::Connection* m_connection;
|
||||
QList<QMatrixClient::Room*> m_rooms;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user