mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Prevent crash when open torrent destination folder
Uses the same workaround as Qt does to call ShellExecute() when you use QDesktopServices::openUrl(). PR #16670. Closes #16423.
This commit is contained in:
parent
e71e97cb68
commit
5960e7dda6
@ -43,6 +43,7 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QScreen>
|
||||
#include <QStyle>
|
||||
#include <QThread>
|
||||
#include <QUrl>
|
||||
#include <QWidget>
|
||||
#include <QWindow>
|
||||
@ -159,15 +160,22 @@ void Utils::Gui::openFolderSelect(const Path &path)
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<PCTSTR>(path.toString().utf16()));
|
||||
auto *thread = QThread::create([path]()
|
||||
{
|
||||
if (SUCCEEDED(::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)))
|
||||
{
|
||||
PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<const wchar_t *>(path.toString().utf16()));
|
||||
if (pidl)
|
||||
{
|
||||
::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);
|
||||
::ILFree(pidl);
|
||||
}
|
||||
if ((hresult == S_OK) || (hresult == S_FALSE))
|
||||
|
||||
::CoUninitialize();
|
||||
}
|
||||
});
|
||||
QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater);
|
||||
thread->start();
|
||||
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
QProcess proc;
|
||||
proc.start(u"xdg-mime"_qs, {u"query"_qs, u"default"_qs, u"inode/directory"_qs});
|
||||
|
Loading…
Reference in New Issue
Block a user