fix(frontend): Mainwindow is blocked when searching.
Description: 修复搜索时主界面阻塞的问题 Log: 修复搜索时主界面阻塞的问题 Bug: http://172.17.66.192/biz/bug-view-43315.html
This commit is contained in:
parent
3ac456f7d6
commit
8707ad5485
|
@ -140,7 +140,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
m_contentFrame->closeWebView();
|
||||
m_search_result_thread->requestInterruption();
|
||||
m_search_result_thread->quit();
|
||||
m_seach_app_thread->stop();
|
||||
// m_seach_app_thread->stop();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -236,7 +236,7 @@ void MainWindow::initUi()
|
|||
m_search_result_thread->requestInterruption();
|
||||
m_search_result_thread->quit();
|
||||
}
|
||||
m_seach_app_thread->stop();
|
||||
// m_seach_app_thread->stop();
|
||||
m_contentFrame->setCurrentIndex(0);
|
||||
} else {
|
||||
m_contentFrame->setCurrentIndex(1);
|
||||
|
@ -321,7 +321,7 @@ void MainWindow::searchContent(QString keyword){
|
|||
m_contentFrame->setSettingList(settingList);
|
||||
|
||||
//应用搜索
|
||||
m_seach_app_thread->stop();
|
||||
// m_seach_app_thread->stop();
|
||||
m_seach_app_thread->startSearch(keyword);
|
||||
|
||||
//文件、文件夹、内容搜索
|
||||
|
@ -410,7 +410,7 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
|||
m_contentFrame->closeWebView();
|
||||
m_search_result_thread->requestInterruption();
|
||||
m_search_result_thread->quit();
|
||||
m_seach_app_thread->stop();
|
||||
// m_seach_app_thread->stop();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -424,7 +424,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
|
|||
m_contentFrame->closeWebView();
|
||||
m_search_result_thread->requestInterruption();
|
||||
m_search_result_thread->quit();
|
||||
m_seach_app_thread->stop();
|
||||
// m_seach_app_thread->stop();
|
||||
}
|
||||
return QWidget::keyPressEvent(event);
|
||||
}
|
||||
|
|
|
@ -1,35 +1,47 @@
|
|||
#include "search-app-thread.h"
|
||||
|
||||
SearchAppThread::SearchAppThread(QObject * parent) : QThread(parent)
|
||||
size_t uniqueSymbol = 0;
|
||||
QMutex m_mutex;
|
||||
|
||||
SearchAppThread::SearchAppThread(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_pool.setMaxThreadCount(1);
|
||||
m_pool.setExpiryTimeout(1000);
|
||||
}
|
||||
|
||||
SearchAppThread::~SearchAppThread()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchAppThread::startSearch 激活线程
|
||||
* @param keyword 关键词
|
||||
*/
|
||||
void SearchAppThread::startSearch(const QString & keyword)
|
||||
{
|
||||
SearchApp *appsearch;
|
||||
appsearch = new SearchApp(keyword);
|
||||
// appsearch->setKeyword(keyword);
|
||||
connect(appsearch, SIGNAL(searchResultApp(const QVector<QStringList>&)), this, SIGNAL(searchResultApp(const QVector<QStringList>&)));
|
||||
m_pool.start(appsearch);
|
||||
}
|
||||
|
||||
|
||||
SearchApp::SearchApp(const QString& keyword, QObject * parent) : QObject(parent)
|
||||
{
|
||||
m_keyword = keyword;
|
||||
m_stop = false;
|
||||
this->start();
|
||||
}
|
||||
|
||||
void SearchAppThread::stop()
|
||||
SearchApp::~SearchApp()
|
||||
{
|
||||
m_stop = true;
|
||||
this->quit();
|
||||
this->wait();
|
||||
m_installed_apps.clear();
|
||||
m_uninstalled_apps.clear();
|
||||
}
|
||||
|
||||
void SearchAppThread::run()
|
||||
///**
|
||||
// * @brief SearchAppThread::startSearch 激活线程
|
||||
// * @param keyword 关键词
|
||||
// */
|
||||
//void SearchApp::setKeyword(const QString & keyword)
|
||||
//{
|
||||
// m_keyword = keyword;
|
||||
//}
|
||||
|
||||
void SearchApp::run()
|
||||
{
|
||||
m_mutex.lock();
|
||||
uniqueSymbol++;
|
||||
m_mutex.unlock();
|
||||
//nameList:应用名,pathList:已安装的是.desktop路径,未安装为空,iconList:已安装的是图标名,未安装的是图标路径
|
||||
QStringList nameList, pathList, iconList, descList;
|
||||
QVector<QStringList> appVector;
|
||||
|
@ -61,6 +73,13 @@ void SearchAppThread::run()
|
|||
appVector.append(pathList);
|
||||
appVector.append(iconList);
|
||||
appVector.append(descList);
|
||||
if (!m_stop)
|
||||
m_mutex.lock();
|
||||
if (uniqueSymbol == uniqueSymbol) {
|
||||
Q_EMIT this->searchResultApp(appVector);
|
||||
}
|
||||
m_mutex.unlock();
|
||||
m_installed_apps.clear();
|
||||
m_uninstalled_apps.clear();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,22 +1,36 @@
|
|||
#ifndef SEARCHAPPTHREAD_H
|
||||
#define SEARCHAPPTHREAD_H
|
||||
#include <QThread>
|
||||
#include <QObject>
|
||||
#include <QRunnable>
|
||||
#include "libsearch.h"
|
||||
|
||||
class SearchAppThread : public QThread
|
||||
class SearchAppThread : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SearchAppThread(QObject * parent = nullptr);
|
||||
~SearchAppThread();
|
||||
~SearchAppThread() = default;
|
||||
void startSearch(const QString&);
|
||||
void stop();
|
||||
private:
|
||||
QThreadPool m_pool;
|
||||
Q_SIGNALS:
|
||||
void searchResultApp(const QVector<QStringList>&);
|
||||
};
|
||||
|
||||
|
||||
class SearchApp : public QObject, public QRunnable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SearchApp(const QString& keyword, QObject * parent = nullptr);
|
||||
~SearchApp();
|
||||
// void setKeyword(const QString&);
|
||||
protected:
|
||||
void run() override;
|
||||
private:
|
||||
QString m_keyword;
|
||||
bool m_stop = false;
|
||||
QMap<NameString,QStringList> m_installed_apps;
|
||||
QMap<NameString,QStringList> m_uninstalled_apps;
|
||||
Q_SIGNALS:
|
||||
|
|
Loading…
Reference in New Issue