xdgdesktopportal: properly fix a dangling pointer
The previous fix didn't actually work, as it kept a reference into a container which could have been muted by the time the reference was going to be used. Use an index instead. Amends 32c09ea5b0f529418eece63de5c3b2c206f62896. Change-Id: Ib855b4a663c281467e46536b98a0ce2b961f19ee Pick-to: 5.15 Task-number: QTBUG-87143 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
227fa93c27
commit
45a0c68c8c
@ -210,7 +210,7 @@ void QXdgDesktopPortalFileDialog::openPortal()
|
||||
qDBusRegisterMetaType<FilterList>();
|
||||
|
||||
FilterList filterList;
|
||||
Filter* selectedFilter = nullptr;
|
||||
auto selectedFilterIndex = filterList.size() - 1;
|
||||
|
||||
d->userVisibleToNameFilter.clear();
|
||||
|
||||
@ -236,7 +236,7 @@ void QXdgDesktopPortalFileDialog::openPortal()
|
||||
filterList << filter;
|
||||
|
||||
if (!d->selectedMimeTypeFilter.isEmpty() && d->selectedMimeTypeFilter == mimeTypefilter)
|
||||
selectedFilter = &filterList.last();
|
||||
selectedFilterIndex = filterList.size() - 1;
|
||||
}
|
||||
} else if (!d->nameFilters.isEmpty()) {
|
||||
for (const QString &nameFilter : d->nameFilters) {
|
||||
@ -265,7 +265,7 @@ void QXdgDesktopPortalFileDialog::openPortal()
|
||||
d->userVisibleToNameFilter.insert(userVisibleName, nameFilter);
|
||||
|
||||
if (!d->selectedNameFilter.isEmpty() && d->selectedNameFilter == nameFilter)
|
||||
selectedFilter = &filterList.last();
|
||||
selectedFilterIndex = filterList.size() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -273,9 +273,8 @@ void QXdgDesktopPortalFileDialog::openPortal()
|
||||
if (!filterList.isEmpty())
|
||||
options.insert(QLatin1String("filters"), QVariant::fromValue(filterList));
|
||||
|
||||
if (selectedFilter) {
|
||||
options.insert(QLatin1String("current_filter"), QVariant::fromValue(*selectedFilter));
|
||||
}
|
||||
if (selectedFilterIndex != -1)
|
||||
options.insert(QLatin1String("current_filter"), QVariant::fromValue(filterList[selectedFilterIndex]));
|
||||
|
||||
options.insert(QLatin1String("handle_token"), QStringLiteral("qt%1").arg(QRandomGenerator::global()->generate()));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user