From b9478e0f0059a119ce638dbf339bcda89efd0302 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 21 Nov 2017 18:07:55 +0800 Subject: [PATCH 1/4] Use Qt5 connect syntax --- src/gui/torrentcreatordlg.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/torrentcreatordlg.cpp b/src/gui/torrentcreatordlg.cpp index 623494adf..9dc836ab9 100644 --- a/src/gui/torrentcreatordlg.cpp +++ b/src/gui/torrentcreatordlg.cpp @@ -67,14 +67,14 @@ TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent, const QString &defaultPath m_ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Create Torrent")); - connect(m_ui->addFileButton, SIGNAL(clicked(bool)), SLOT(onAddFileButtonClicked())); - connect(m_ui->addFolderButton, SIGNAL(clicked(bool)), SLOT(onAddFolderButtonClicked())); - connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(onCreateButtonClicked())); - connect(m_ui->buttonCalcTotalPieces, &QAbstractButton::clicked, this, &TorrentCreatorDlg::updatePiecesCount); - - connect(m_creatorThread, SIGNAL(creationSuccess(QString, QString)), this, SLOT(handleCreationSuccess(QString, QString))); - connect(m_creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString))); - connect(m_creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int))); + connect(m_ui->addFileButton, &QPushButton::clicked, this, &TorrentCreatorDlg::onAddFileButtonClicked); + connect(m_ui->addFolderButton, &QPushButton::clicked, this, &TorrentCreatorDlg::onAddFolderButtonClicked); + connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &TorrentCreatorDlg::onCreateButtonClicked); + connect(m_ui->buttonCalcTotalPieces, &QPushButton::clicked, this, &TorrentCreatorDlg::updatePiecesCount); + + connect(m_creatorThread, &BitTorrent::TorrentCreatorThread::creationSuccess, this, &TorrentCreatorDlg::handleCreationSuccess); + connect(m_creatorThread, &BitTorrent::TorrentCreatorThread::creationFailure, this, &TorrentCreatorDlg::handleCreationFailure); + connect(m_creatorThread, &BitTorrent::TorrentCreatorThread::updateProgress, this, &TorrentCreatorDlg::updateProgressBar); loadSettings(); updateInputPath(defaultPath); From c3de2310c5b084f0ab045d99edb18030b280512a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 21 Nov 2017 18:08:34 +0800 Subject: [PATCH 2/4] Avoid double delete on close --- src/gui/torrentcreatordlg.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/gui/torrentcreatordlg.cpp b/src/gui/torrentcreatordlg.cpp index 9dc836ab9..d7e1f8dc1 100644 --- a/src/gui/torrentcreatordlg.cpp +++ b/src/gui/torrentcreatordlg.cpp @@ -86,9 +86,6 @@ TorrentCreatorDlg::~TorrentCreatorDlg() { saveSettings(); - if (m_creatorThread) - delete m_creatorThread; - delete m_ui; } From 034d71dce3ba7ab4dacb130b6766beabddbe2b4d Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 21 Nov 2017 18:23:39 +0800 Subject: [PATCH 3/4] Wrap function into anonymous namespace --- src/base/bittorrent/torrentcreatorthread.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/base/bittorrent/torrentcreatorthread.cpp b/src/base/bittorrent/torrentcreatorthread.cpp index bfa8ca83e..c8d19c16e 100644 --- a/src/base/bittorrent/torrentcreatorthread.cpp +++ b/src/base/bittorrent/torrentcreatorthread.cpp @@ -35,8 +35,8 @@ #include #include #include -#include #include +#include #include @@ -44,16 +44,19 @@ #include "base/utils/misc.h" #include "base/utils/string.h" -namespace libt = libtorrent; -using namespace BitTorrent; - -// do not include files and folders whose -// name starts with a . -bool fileFilter(const std::string &f) +namespace { - return !Utils::Fs::fileName(QString::fromStdString(f)).startsWith('.'); + // do not include files and folders whose + // name starts with a . + bool fileFilter(const std::string &f) + { + return !Utils::Fs::fileName(QString::fromStdString(f)).startsWith('.'); + } } +namespace libt = libtorrent; +using namespace BitTorrent; + TorrentCreatorThread::TorrentCreatorThread(QObject *parent) : QThread(parent) , m_private(false) From 433b5a46cf2e3bf15fd8b0c5e6e7134807907486 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 21 Nov 2017 18:29:22 +0800 Subject: [PATCH 4/4] Fix crash when aborting a torrent creation process. Closes #7783. The wait time wasn't long enough causing the thread to terminate prematurely. Also, to avoid crashing qbt entirely when creating a torrent for a very big file, I decided to wait indefinitely here. --- src/base/bittorrent/torrentcreatorthread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/bittorrent/torrentcreatorthread.cpp b/src/base/bittorrent/torrentcreatorthread.cpp index c8d19c16e..27265da5c 100644 --- a/src/base/bittorrent/torrentcreatorthread.cpp +++ b/src/base/bittorrent/torrentcreatorthread.cpp @@ -67,7 +67,7 @@ TorrentCreatorThread::TorrentCreatorThread(QObject *parent) TorrentCreatorThread::~TorrentCreatorThread() { requestInterruption(); - wait(1000); + wait(); } void TorrentCreatorThread::create(const QString &inputPath, const QString &savePath, const QStringList &trackers,