@@ -382,7 +382,6 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
382
382
// based timer interface
383
383
RPCSetTimerInterfaceIfUnset (rpcTimerInterface);
384
384
385
- startExecutor ();
386
385
setTrafficGraphRange (INITIAL_TRAFFIC_GRAPH_MINS);
387
386
388
387
ui->detailWidget ->hide ();
@@ -396,7 +395,6 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
396
395
RPCConsole::~RPCConsole ()
397
396
{
398
397
GUIUtil::saveWindowGeometry (" nRPCConsoleWindow" , this );
399
- Q_EMIT stopExecutor ();
400
398
RPCUnsetTimerInterface (rpcTimerInterface);
401
399
delete rpcTimerInterface;
402
400
delete ui;
@@ -565,6 +563,14 @@ void RPCConsole::setClientModel(ClientModel *model)
565
563
autoCompleter = new QCompleter (wordList, this );
566
564
ui->lineEdit ->setCompleter (autoCompleter);
567
565
autoCompleter->popup ()->installEventFilter (this );
566
+ // Start thread to execute RPC commands.
567
+ startExecutor ();
568
+ }
569
+ if (!model) {
570
+ // Client model is being set to 0, this means shutdown() is about to be called.
571
+ // Make sure we clean up the executor thread
572
+ Q_EMIT stopExecutor ();
573
+ thread.wait ();
568
574
}
569
575
}
570
576
@@ -759,26 +765,24 @@ void RPCConsole::browseHistory(int offset)
759
765
760
766
void RPCConsole::startExecutor ()
761
767
{
762
- QThread *thread = new QThread;
763
768
RPCExecutor *executor = new RPCExecutor ();
764
- executor->moveToThread (thread);
769
+ executor->moveToThread (& thread);
765
770
766
771
// Replies from executor object must go to this object
767
772
connect (executor, SIGNAL (reply (int ,QString)), this , SLOT (message (int ,QString)));
768
773
// Requests from this object must go to executor
769
774
connect (this , SIGNAL (cmdRequest (QString)), executor, SLOT (request (QString)));
770
775
771
776
// On stopExecutor signal
772
- // - queue executor for deletion (in execution thread)
773
777
// - quit the Qt event loop in the execution thread
774
- connect (this , SIGNAL (stopExecutor ()), executor , SLOT (deleteLater ()));
775
- connect ( this , SIGNAL ( stopExecutor ()), thread, SLOT ( quit ()));
776
- // Queue the thread for deletion (in this thread) when it is finished
777
- connect (thread, SIGNAL (finished ()), thread , SLOT (deleteLater ()));
778
+ connect (this , SIGNAL (stopExecutor ()), &thread , SLOT (quit ()));
779
+ // - queue executor for deletion (in execution thread)
780
+ connect (& thread, SIGNAL ( finished ()), executor, SLOT ( deleteLater ()), Qt::DirectConnection);
781
+ connect (& thread, SIGNAL (finished ()), this , SLOT (test ()), Qt::DirectConnection );
778
782
779
783
// Default implementation of QThread::run() simply spins up an event loop in the thread,
780
784
// which is what we want.
781
- thread-> start ();
785
+ thread. start ();
782
786
}
783
787
784
788
void RPCConsole::on_tabWidget_currentChanged (int index)
0 commit comments