Skip to content

Commit

Permalink
Merge pull request #1270 from xiaoyifang/fix/dictserver
Browse files Browse the repository at this point in the history
fix: dictserver freeze gui
  • Loading branch information
xiaoyifang authored Nov 6, 2023
2 parents 764fef9 + c7d7931 commit 2799b41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 7 additions & 10 deletions src/dict/dictserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool connectToServer( QTcpSocket & socket, QString const & url, QString & errorS

socket.connectToHost( serverUrl.host(), port );
if ( socket.state() != QTcpSocket::ConnectedState ) {
if ( !socket.waitForConnected( 100 ) )
if ( !socket.waitForConnected( 2000 ) )
break;
}

Expand Down Expand Up @@ -344,14 +344,12 @@ class DictServerWordSearchRequest: public Dictionary::WordSearchRequest
QString errorString;
QFuture< void > f;
DictServerDictionary & dict;
QTcpSocket * socket;

public:

DictServerWordSearchRequest( wstring const & word_, DictServerDictionary & dict_ ):
word( word_ ),
dict( dict_ ),
socket( 0 )
dict( dict_ )
{
f = QtConcurrent::run( [ this ]() {
this->run();
Expand All @@ -362,7 +360,8 @@ class DictServerWordSearchRequest: public Dictionary::WordSearchRequest

~DictServerWordSearchRequest() override
{
f.waitForFinished();
//with this line ,the gui will be frozened?
// f.waitForFinished();
}

void cancel() override;
Expand All @@ -375,7 +374,7 @@ void DictServerWordSearchRequest::run()
return;
}

socket = new QTcpSocket;
auto socket = new QTcpSocket;

if ( !socket ) {
finish();
Expand Down Expand Up @@ -514,14 +513,12 @@ class DictServerArticleRequest: public Dictionary::DataRequest
QString errorString;
QFuture< void > f;
DictServerDictionary & dict;
QTcpSocket * socket;

public:

DictServerArticleRequest( wstring const & word_, DictServerDictionary & dict_ ):
word( word_ ),
dict( dict_ ),
socket( 0 )
dict( dict_ )
{
f = QtConcurrent::run( [ this ]() {
this->run();
Expand All @@ -545,7 +542,7 @@ void DictServerArticleRequest::run()
return;
}

socket = new QTcpSocket;
auto socket = new QTcpSocket;

if ( !socket ) {
finish();
Expand Down
4 changes: 3 additions & 1 deletion src/wordfinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ void WordFinder::updateResults()

void WordFinder::cancelSearches()
{
for ( auto & queuedRequest : queuedRequests )
for ( auto & queuedRequest : queuedRequests ) {
disconnect( queuedRequest.get(), 0, 0, 0 );
queuedRequest->cancel();
}
}

0 comments on commit 2799b41

Please sign in to comment.