summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJøger Hansegård <joger.hansegard@qt.io>2023-08-08 14:49:28 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-08-15 06:59:19 +0000
commit9a5ccc89daede1f289b2302430bdd41f9e56022d (patch)
treeec61cf4d08cf3056d3a1d9e4db204ec12ff0228f /examples
parentf79c30ee8b4353cfe4d11eb1f6dcd8602be2f05a (diff)
[ActiveQt] qutlook sample crashes with distribution lists
The qutlook sample may crash if the contact list contains items that are not regular contacts, for example distribution lists. The crash occur because items such as distribution lists do not have the requested properties (FirstName, LastName etc). This patch works around this issue by checking if the contact list item is a contact before attempting to access the requested properties. A side effect is that non-contact entries show up as blank lines in the address list. In addition, the patch fixes an issue where the qutlook app crashes if creating the Outlook COM server fails. This was related to an uninitialized variable (AddressBookModel::folderItems) Task-number: QTBUG-111191 Change-Id: I6abfdaba4a49ef85bc245b26779b8bfdc409887b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit 58a3cfe8574550872d47d7e08ae9b62e3b99bfd1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/activeqt/qutlook/addressview.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/examples/activeqt/qutlook/addressview.cpp b/examples/activeqt/qutlook/addressview.cpp
index 2f5242a..f3d4fc7 100644
--- a/examples/activeqt/qutlook/addressview.cpp
+++ b/examples/activeqt/qutlook/addressview.cpp
@@ -23,7 +23,7 @@ public:
private:
Outlook::Application outlook;
- Outlook::Items * contactItems;
+ Outlook::Items *folderItems = nullptr;
mutable QHash<QModelIndex, QStringList> cache;
};
@@ -36,10 +36,10 @@ AddressBookModel::AddressBookModel(AddressView *parent)
Outlook::NameSpace session(outlook.Session());
session.Logon();
Outlook::MAPIFolder *folder = session.GetDefaultFolder(Outlook::olFolderContacts);
- contactItems = new Outlook::Items(folder->Items());
- connect(contactItems, SIGNAL(ItemAdd(IDispatch*)), parent, SLOT(updateOutlook()));
- connect(contactItems, SIGNAL(ItemChange(IDispatch*)), parent, SLOT(updateOutlook()));
- connect(contactItems, SIGNAL(ItemRemove()), parent, SLOT(updateOutlook()));
+ folderItems = new Outlook::Items(folder->Items());
+ connect(folderItems, SIGNAL(ItemAdd(IDispatch*)), parent, SLOT(updateOutlook()));
+ connect(folderItems, SIGNAL(ItemChange(IDispatch*)), parent, SLOT(updateOutlook()));
+ connect(folderItems, SIGNAL(ItemRemove()), parent, SLOT(updateOutlook()));
delete folder;
}
@@ -48,7 +48,7 @@ AddressBookModel::AddressBookModel(AddressView *parent)
//! [1] //! [2]
AddressBookModel::~AddressBookModel()
{
- delete contactItems;
+ delete folderItems;
if (!outlook.isNull())
Outlook::NameSpace(outlook.Session()).Logoff();
@@ -57,7 +57,7 @@ AddressBookModel::~AddressBookModel()
//! [2] //! [3]
int AddressBookModel::rowCount(const QModelIndex &) const
{
- return contactItems ? contactItems->Count() : 0;
+ return folderItems ? folderItems->Count() : 0;
}
int AddressBookModel::columnCount(const QModelIndex & /*parent*/) const
@@ -97,8 +97,11 @@ QVariant AddressBookModel::data(const QModelIndex &index, int role) const
if (cache.contains(index)) {
data = cache.value(index);
} else {
- Outlook::ContactItem contact(contactItems->Item(index.row() + 1));
- data << contact.FirstName() << contact.LastName() << contact.HomeAddress() << contact.Email1Address();
+ Outlook::ContactItem contact(folderItems->Item(index.row() + 1));
+
+ if (contact.Class() == Outlook::OlObjectClass::olContact)
+ data << contact.FirstName() << contact.LastName() << contact.HomeAddress() << contact.Email1Address();
+
cache.insert(index, data);
}
@@ -111,7 +114,10 @@ QVariant AddressBookModel::data(const QModelIndex &index, int role) const
//! [5] //! [6]
void AddressBookModel::changeItem(const QModelIndex &index, const QString &firstName, const QString &lastName, const QString &address, const QString &email)
{
- Outlook::ContactItem item(contactItems->Item(index.row() + 1));
+ Outlook::ContactItem item(folderItems->Item(index.row() + 1));
+
+ if (item.Class() != Outlook::OlObjectClass::olContact)
+ return; // Not a contact
item.SetFirstName(firstName);
item.SetLastName(lastName);