mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-24 07:05:25 -07: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
f40e92f186
commit
e5894831ec
1 changed files with 16 additions and 8 deletions
|
@ -44,6 +44,7 @@
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
#include <QThread>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
@ -167,15 +168,22 @@ void Utils::Gui::openFolderSelect(const QString &absolutePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
auto *thread = QThread::create([path]()
|
||||||
PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<PCTSTR>(Utils::Fs::toNativePath(path).utf16()));
|
|
||||||
if (pidl)
|
|
||||||
{
|
{
|
||||||
::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);
|
if (SUCCEEDED(::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)))
|
||||||
::ILFree(pidl);
|
{
|
||||||
}
|
PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<const wchar_t *>(Utils::Fs::toNativePath(path).utf16()));
|
||||||
if ((hresult == S_OK) || (hresult == S_FALSE))
|
if (pidl)
|
||||||
::CoUninitialize();
|
{
|
||||||
|
::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);
|
||||||
|
::ILFree(pidl);
|
||||||
|
}
|
||||||
|
|
||||||
|
::CoUninitialize();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater);
|
||||||
|
thread->start();
|
||||||
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||||
QProcess proc;
|
QProcess proc;
|
||||||
proc.start("xdg-mime", {"query", "default", "inode/directory"});
|
proc.start("xdg-mime", {"query", "default", "inode/directory"});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue