mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-02 01:56:23 +00:00
fix(src/components/contacts/ContactsListModel): set parent of contacts (avoid leaks)
This commit is contained in:
parent
e66f46f318
commit
9a269a14fe
3 changed files with 7 additions and 9 deletions
|
|
@ -30,7 +30,7 @@ using namespace std;
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
ContactModel::ContactModel (shared_ptr<linphone::Friend> linphone_friend) {
|
ContactModel::ContactModel (QObject *parent, shared_ptr<linphone::Friend> linphone_friend) : QObject(parent) {
|
||||||
m_linphone_friend = linphone_friend;
|
m_linphone_friend = linphone_friend;
|
||||||
m_vcard = make_shared<VcardModel>(linphone_friend->getVcard());
|
m_vcard = make_shared<VcardModel>(linphone_friend->getVcard());
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ ContactModel::ContactModel (shared_ptr<linphone::Friend> linphone_friend) {
|
||||||
m_linphone_friend->setData("contact-model", *this);
|
m_linphone_friend->setData("contact-model", *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContactModel::ContactModel (VcardModel *vcard) {
|
ContactModel::ContactModel (QObject *parent, VcardModel *vcard) : QObject(parent) {
|
||||||
Q_ASSERT(vcard != nullptr);
|
Q_ASSERT(vcard != nullptr);
|
||||||
|
|
||||||
QQmlEngine *engine = App::getInstance()->getEngine();
|
QQmlEngine *engine = App::getInstance()->getEngine();
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ class ContactModel : public QObject {
|
||||||
friend class SmartSearchBarModel;
|
friend class SmartSearchBarModel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ContactModel (std::shared_ptr<linphone::Friend> linphone_friend);
|
ContactModel (QObject *parent, std::shared_ptr<linphone::Friend> linphone_friend);
|
||||||
ContactModel (VcardModel *vcard);
|
ContactModel (QObject *parent, VcardModel *vcard);
|
||||||
~ContactModel () = default;
|
~ContactModel () = default;
|
||||||
|
|
||||||
std::shared_ptr<VcardModel> getVcardModel () const {
|
std::shared_ptr<VcardModel> getVcardModel () const {
|
||||||
|
|
|
||||||
|
|
@ -37,13 +37,11 @@ ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(pare
|
||||||
|
|
||||||
// Init contacts with linphone friends list.
|
// Init contacts with linphone friends list.
|
||||||
for (const auto &friend_ : m_linphone_friends->getFriends()) {
|
for (const auto &friend_ : m_linphone_friends->getFriends()) {
|
||||||
ContactModel *contact = new ContactModel(friend_);
|
ContactModel *contact = new ContactModel(this, friend_);
|
||||||
|
|
||||||
// See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership
|
// See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership
|
||||||
// The returned value must have a explicit parent or a QQmlEngine::CppOwnership.
|
// The returned value must have a explicit parent or a QQmlEngine::CppOwnership.
|
||||||
App::getInstance()->getEngine()->setObjectOwnership(
|
App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership);
|
||||||
contact, QQmlEngine::CppOwnership
|
|
||||||
);
|
|
||||||
|
|
||||||
addContact(contact);
|
addContact(contact);
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +98,7 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
ContactModel *ContactsListModel::addContact (VcardModel *vcard) {
|
ContactModel *ContactsListModel::addContact (VcardModel *vcard) {
|
||||||
ContactModel *contact = new ContactModel(vcard);
|
ContactModel *contact = new ContactModel(this, vcard);
|
||||||
App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership);
|
App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership);
|
||||||
|
|
||||||
qInfo() << "Add contact:" << contact;
|
qInfo() << "Add contact:" << contact;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue