From 732b6f5ae7e96b7f13e81c951e88e946ea31138b Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Fri, 2 May 2014 14:06:45 +0200 Subject: [PATCH] Remove duplicate CVoiceVatlib object. Move the one in Client into its own thread instead refs #226 --- samples/voiceclient/client.cpp | 6 ++++++ samples/voiceclient/client.h | 3 +++ samples/voiceclient/main.cpp | 18 ++++-------------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/samples/voiceclient/client.cpp b/samples/voiceclient/client.cpp index 14c882af3..63d939c62 100644 --- a/samples/voiceclient/client.cpp +++ b/samples/voiceclient/client.cpp @@ -19,6 +19,9 @@ Client::Client(QObject *parent) : QObject(parent), m_voice(new BlackCore::CVoiceVatlib()) { + m_voice->moveToThread(&m_threadVoice); + m_threadVoice.start(); + using namespace BlackCore; connect(m_voice, &IVoice::squelchTestFinished, this, &Client::onSquelchTestFinished); connect(m_voice, &IVoice::micTestFinished, this, &Client::onMicTestFinished); @@ -91,6 +94,9 @@ void Client::echo(QTextStream &line) void Client::exit(QTextStream &) { + qDebug() << "Shutting down..."; + m_threadVoice.quit(); + m_threadVoice.wait(5000); emit quit(); } diff --git a/samples/voiceclient/client.h b/samples/voiceclient/client.h index 04d928ad0..651bfaf9b 100644 --- a/samples/voiceclient/client.h +++ b/samples/voiceclient/client.h @@ -11,6 +11,7 @@ #include #include #include +#include class Client : public QObject { @@ -18,6 +19,7 @@ class Client : public QObject public: Client(QObject *parent = nullptr); + ~Client() { if(m_voice) m_voice->deleteLater(); } signals: void quit(); @@ -56,6 +58,7 @@ private slots: private: QMap> m_commands; BlackCore::IVoice *m_voice; + QThread m_threadVoice; }; diff --git a/samples/voiceclient/main.cpp b/samples/voiceclient/main.cpp index 5d31ef8b9..cfe69fdc1 100644 --- a/samples/voiceclient/main.cpp +++ b/samples/voiceclient/main.cpp @@ -12,7 +12,7 @@ #include #include -#include + using namespace BlackMisc::Audio; @@ -22,20 +22,10 @@ int main(int argc, char *argv[]) Client client(&app); BlackMisc::registerMetadata(); BlackCore::registerMetadata(); - BlackCore::IVoice *m_voice = new BlackCore::CVoiceVatlib(); - QThread m_voiceThread; - m_voice->moveToThread(&m_voiceThread); - m_voiceThread.start(); LineReader reader; - QObject::connect(&reader, SIGNAL(command(const QString &)), &client, SLOT(command(const QString &))); - QObject::connect(&client, &Client::quit, [&] () - { - qDebug() << "Shutting down..."; - reader.terminate(); - m_voiceThread.quit(); - m_voiceThread.wait(5000); - qApp->quit(); - }); + QObject::connect(&reader, SIGNAL(command(const QString &)), &client, SLOT(command(const QString &)), Qt::QueuedConnection); + QObject::connect(&client, SIGNAL(quit()), &reader, SLOT(terminate())); + QObject::connect(&client, SIGNAL(quit()), &app, SLOT(quit())); reader.start(); app.exec();