diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bf0561b..9fa7359 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -162,7 +162,7 @@ void MainWindow::initUi() connect(m_settingsWidget, &SettingsWidget::settingWidgetClosed, this, [ = ]() { QTimer::singleShot(100, this, [ = ] { clearSearchResult(); - m_search_result_thread->start(); +// m_search_result_thread->start(); this->setWindowState(this->windowState() & ~Qt::WindowMinimized); this->raise(); this->showNormal(); @@ -192,10 +192,17 @@ void MainWindow::initUi() &MainWindow::primaryScreenChangedSlot); connect(m_searchLayout, &UkuiSearchBarHLayout::textChanged, this, [ = ](QString text) { if (text == "") { + if (m_search_result_thread->isInterruptionRequested()) { + m_search_result_thread->requestInterruption(); + m_search_result_thread->quit(); + } m_contentFrame->setCurrentIndex(0); } else { m_contentFrame->setCurrentIndex(1); // QTimer::singleShot(50,this,[=](){ + if (! m_search_result_thread->isInterruptionRequested()) { + m_search_result_thread->start(); + } searchContent(text); // }); } @@ -215,7 +222,7 @@ void MainWindow::bootOptionsFilter(QString opt) this->show(); this->raise(); this->activateWindow(); - m_search_result_thread->start(); +// m_search_result_thread->start(); } /** @@ -299,6 +306,7 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r switch (event->response_type & ~0x80) { case XCB_FOCUS_OUT: this->hide(); + m_search_result_thread->requestInterruption(); m_search_result_thread->quit(); break; } diff --git a/src/search-result.cpp b/src/search-result.cpp index defc5ae..c3a74b4 100644 --- a/src/search-result.cpp +++ b/src/search-result.cpp @@ -1,20 +1,30 @@ #include "search-result.h" -#include SearchResult::SearchResult(QObject * parent) : QThread(parent) { m_mainwindow = static_cast(parent); +// m_timer = new QTimer; +// QObject::connect(m_timer, &QTimer::timeout, this, [ = ](){ +// qWarning()<<"-------------------------------------------------------"; +// m_timer->stop(); +// this->requestInterruption(); +// }); } SearchResult::~SearchResult() { - +// if (m_timer) { +// delete m_timer; +// m_timer = NULL; +// } } void SearchResult::run() { + QTimer * m_timer = new QTimer; int emptyLists = 0; while(!isInterruptionRequested()) { + qWarning()<<"--------------------"; emptyLists = 0; m_mainwindow->m_searcher->m_mutex1.lock(); if (!m_mainwindow->m_search_result_file->isEmpty()) { @@ -42,5 +52,15 @@ void SearchResult::run() emptyLists ++; m_mainwindow->m_searcher->m_mutex3.unlock(); } + if (m_timer->isActive() && m_timer->remainingTime() < 0.01) { + this->requestInterruption(); + } + if (emptyLists == 3 && !m_timer->isActive()) { + m_timer->start(); + } else if (emptyLists != 3) { + m_timer->stop(); + } else { + msleep(100); + } } } diff --git a/src/search-result.h b/src/search-result.h index e2057fe..c4594cd 100644 --- a/src/search-result.h +++ b/src/search-result.h @@ -2,6 +2,7 @@ #define SEARCHRESULT_H #include #include +#include #include "mainwindow.h" class SearchResult : public QThread @@ -15,6 +16,7 @@ protected: private: MainWindow * m_mainwindow = nullptr; +// QTimer * m_timer = nullptr; Q_SIGNALS: void searchResultFile(const QString&);