fix: crash on quit while fullindex is creating

This commit is contained in:
Xiao YiFang 2022-10-11 22:09:15 +08:00
parent bf625dc550
commit 2d8ba54a1d
2 changed files with 5 additions and 14 deletions

View file

@ -36,6 +36,7 @@ void Indexing::run()
{ {
try try
{ {
timerThread->start();
// First iteration - dictionaries with no more MaxDictionarySizeForFastSearch articles // First iteration - dictionaries with no more MaxDictionarySizeForFastSearch articles
for( size_t x = 0; x < dictionaries.size(); x++ ) for( size_t x = 0; x < dictionaries.size(); x++ )
{ {
@ -63,6 +64,9 @@ void Indexing::run()
dictionaries.at( x )->makeFTSIndex( isCancelled, false ); dictionaries.at( x )->makeFTSIndex( isCancelled, false );
} }
} }
timerThread->quit();
timerThread->wait();
} }
catch( std::exception &ex ) catch( std::exception &ex )
{ {

View file

@ -89,28 +89,15 @@ public:
timerThread(new QThread(this)) timerThread(new QThread(this))
{ {
connect(timer, &QTimer::timeout, this, &Indexing::timeout); connect(timer, &QTimer::timeout, this, &Indexing::timeout);
// timer->start(2000);
timer->moveToThread(timerThread); timer->moveToThread(timerThread);
connect(timerThread, &QThread::started, timer, [this](){timer->start(2000);}); connect(timerThread, &QThread::started, timer, [this](){timer->start(2000);});
connect(timerThread, &QThread::finished, timer, &QTimer::stop); connect(timerThread, &QThread::finished, timer, &QTimer::stop);
timerThread->start();
} }
~Indexing() ~Indexing()
{ {
if(timerThread){
qInfo()<<"delete thread";
timerThread->quit();
timerThread->wait();
delete timerThread;
timerThread = nullptr;
}
if(timer){
qInfo()<<"delete timer";
delete timer;
timer = nullptr;
}
emit sendNowIndexingName( QString() ); emit sendNowIndexingName( QString() );
hasExited.release(); hasExited.release();