mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
searchengine: fix crash when closing tab with running search
If a tab is closed, the search process gets terminated. This can take a while and by the time searchFinished() is executed, activeSearchTab is null, leading to a crash. Fix this by waiting for the process to terminate and make sure activeSearchTab is not null when used.
This commit is contained in:
parent
a51a855870
commit
be47c35cba
1 changed files with 21 additions and 14 deletions
|
@ -207,13 +207,16 @@ void SearchEngine::on_search_button_clicked()
|
||||||
search_stopped = true;
|
search_stopped = true;
|
||||||
if (searchTimeout->isActive())
|
if (searchTimeout->isActive())
|
||||||
searchTimeout->stop();
|
searchTimeout->stop();
|
||||||
|
|
||||||
|
searchProcess->waitForFinished(1000);
|
||||||
|
|
||||||
if (search_button->text() != tr("Search")) {
|
if (search_button->text() != tr("Search")) {
|
||||||
search_button->setText(tr("Search"));
|
search_button->setText(tr("Search"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
allTabsSetActiveState(false);
|
allTabsSetActiveState(false);
|
||||||
}
|
}
|
||||||
searchProcess->waitForFinished();
|
|
||||||
// Reload environment variables (proxy)
|
// Reload environment variables (proxy)
|
||||||
searchProcess->setEnvironment(QProcess::systemEnvironment());
|
searchProcess->setEnvironment(QProcess::systemEnvironment());
|
||||||
|
|
||||||
|
@ -249,7 +252,7 @@ void SearchEngine::on_search_button_clicked()
|
||||||
nb_search_results = 0;
|
nb_search_results = 0;
|
||||||
search_result_line_truncated.clear();
|
search_result_line_truncated.clear();
|
||||||
//on change le texte du label courrant
|
//on change le texte du label courrant
|
||||||
currentSearchTab->getCurrentLabel()->setText(tr("Results") + " <i>(0)</i>:");
|
activeSearchTab->getCurrentLabel()->setText(tr("Results") + " <i>(0)</i>:");
|
||||||
// Launch search
|
// Launch search
|
||||||
searchProcess->start(misc::pythonExecutable(), params, QIODevice::ReadOnly);
|
searchProcess->start(misc::pythonExecutable(), params, QIODevice::ReadOnly);
|
||||||
searchTimeout->start(180000); // 3min
|
searchTimeout->start(180000); // 3min
|
||||||
|
@ -301,7 +304,7 @@ void SearchEngine::searchStarted()
|
||||||
{
|
{
|
||||||
// Update SearchEngine widgets
|
// Update SearchEngine widgets
|
||||||
activeSearchTab->status = tr("Searching...");
|
activeSearchTab->status = tr("Searching...");
|
||||||
search_status->setText(activeSearchTab->status);
|
search_status->setText(currentSearchTab->status);
|
||||||
search_status->repaint();
|
search_status->repaint();
|
||||||
search_button->setText(tr("Stop"));
|
search_button->setText(tr("Stop"));
|
||||||
}
|
}
|
||||||
|
@ -321,7 +324,6 @@ void SearchEngine::readSearchOutput()
|
||||||
search_result_line_truncated = lines_list.takeLast().trimmed();
|
search_result_line_truncated = lines_list.takeLast().trimmed();
|
||||||
foreach (const QByteArray &line, lines_list)
|
foreach (const QByteArray &line, lines_list)
|
||||||
appendSearchResult(QString::fromUtf8(line));
|
appendSearchResult(QString::fromUtf8(line));
|
||||||
if (activeSearchTab)
|
|
||||||
activeSearchTab->getCurrentLabel()->setText(tr("Results") + QString::fromUtf8(" <i>(") + QString::number(nb_search_results) + QString::fromUtf8(")</i>:"));
|
activeSearchTab->getCurrentLabel()->setText(tr("Results") + QString::fromUtf8(" <i>(") + QString::number(nb_search_results) + QString::fromUtf8(")</i>:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,6 +442,11 @@ void SearchEngine::searchFinished(int exitcode, QProcess::ExitStatus)
|
||||||
bool useNotificationBalloons = Preferences::instance()->useProgramNotification();
|
bool useNotificationBalloons = Preferences::instance()->useProgramNotification();
|
||||||
if (useNotificationBalloons && mp_mainWindow->getCurrentTabWidget() != this)
|
if (useNotificationBalloons && mp_mainWindow->getCurrentTabWidget() != this)
|
||||||
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished"));
|
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished"));
|
||||||
|
|
||||||
|
if (activeSearchTab.isNull())
|
||||||
|
// The active tab was closed
|
||||||
|
return;
|
||||||
|
|
||||||
if (exitcode) {
|
if (exitcode) {
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
activeSearchTab->status = tr("Search aborted");
|
activeSearchTab->status = tr("Search aborted");
|
||||||
|
@ -458,13 +465,9 @@ void SearchEngine::searchFinished(int exitcode, QProcess::ExitStatus)
|
||||||
activeSearchTab->status = tr("Search has finished");
|
activeSearchTab->status = tr("Search has finished");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
search_status->setText(currentSearchTab->status);
|
||||||
if (activeSearchTab)
|
|
||||||
if (currentSearchTab == activeSearchTab) search_status->setText(activeSearchTab->status);
|
|
||||||
activeSearchTab->getCurrentLabel()->setText(tr("Results", "i.e: Search results") + QString::fromUtf8(" <i>(") + QString::number(nb_search_results) + QString::fromUtf8(")</i>:"));
|
|
||||||
activeSearchTab->isActive = false;
|
activeSearchTab->isActive = false;
|
||||||
activeSearchTab = 0;
|
activeSearchTab = 0;
|
||||||
|
|
||||||
search_button->setText(tr("Search"));
|
search_button->setText(tr("Search"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,9 +476,11 @@ void SearchEngine::searchFinished(int exitcode, QProcess::ExitStatus)
|
||||||
// file url | file name | file size | nb seeds | nb leechers | Search engine url
|
// file url | file name | file size | nb seeds | nb leechers | Search engine url
|
||||||
void SearchEngine::appendSearchResult(const QString &line)
|
void SearchEngine::appendSearchResult(const QString &line)
|
||||||
{
|
{
|
||||||
if (!activeSearchTab) {
|
if (activeSearchTab.isNull()) {
|
||||||
if (searchProcess->state() != QProcess::NotRunning)
|
if (searchProcess->state() != QProcess::NotRunning) {
|
||||||
searchProcess->terminate();
|
searchProcess->terminate();
|
||||||
|
searchProcess->waitForFinished(1000);
|
||||||
|
}
|
||||||
if (searchTimeout->isActive())
|
if (searchTimeout->isActive())
|
||||||
searchTimeout->stop();
|
searchTimeout->stop();
|
||||||
search_stopped = true;
|
search_stopped = true;
|
||||||
|
@ -521,20 +526,22 @@ void SearchEngine::appendSearchResult(const QString &line)
|
||||||
void SearchEngine::closeTab(int index)
|
void SearchEngine::closeTab(int index)
|
||||||
{
|
{
|
||||||
// Search is run for active tab so if user decided to close it, then stop search
|
// Search is run for active tab so if user decided to close it, then stop search
|
||||||
if (activeSearchTab && index == tabWidget->indexOf(activeSearchTab)) {
|
if (!activeSearchTab.isNull() && index == tabWidget->indexOf(activeSearchTab)) {
|
||||||
qDebug("Closed active search Tab");
|
qDebug("Closed active search Tab");
|
||||||
if (searchProcess->state() != QProcess::NotRunning)
|
if (searchProcess->state() != QProcess::NotRunning)
|
||||||
searchProcess->terminate();
|
searchProcess->terminate();
|
||||||
|
searchProcess->waitForFinished(1000);
|
||||||
|
}
|
||||||
if (searchTimeout->isActive())
|
if (searchTimeout->isActive())
|
||||||
searchTimeout->stop();
|
searchTimeout->stop();
|
||||||
search_stopped = true;
|
search_stopped = true;
|
||||||
if (currentSearchTab == activeSearchTab) currentSearchTab = 0;
|
|
||||||
activeSearchTab = 0;
|
activeSearchTab = 0;
|
||||||
}
|
}
|
||||||
delete all_tab.takeAt(index);
|
delete all_tab.takeAt(index);
|
||||||
if (!all_tab.size()) {
|
if (!all_tab.size()) {
|
||||||
download_button->setEnabled(false);
|
download_button->setEnabled(false);
|
||||||
goToDescBtn->setEnabled(false);
|
goToDescBtn->setEnabled(false);
|
||||||
|
search_status->setText(tr("Stopped"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue