summaryrefslogtreecommitdiffstats
path: root/examples/speech/hello_speak/mainwindow.cpp
diff options
context:
space:
mode:
authorJani Korteniemi <jani.korteniemi@qt.io>2021-12-31 15:32:41 +0200
committerJani Korteniemi <jani.korteniemi@qt.io>2022-02-04 09:33:45 +0200
commit98bd3fe90bdabe24532164263dc17cb750bee8c5 (patch)
tree340d1eb06726c55098a6473b9ff409423c3d0701 /examples/speech/hello_speak/mainwindow.cpp
parent76a40efbba8ed0f0a6029854336528b42544874d (diff)
Fix QtSpeech example querying locales before initialising
Added separate function for handling the query locales, which is executed when QTextToSpeech object is ready. Task-number: QTBUG-66034 Change-Id: I2b0fa69f9e66a0d6be65b1a221ab024a2d6700b5 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'examples/speech/hello_speak/mainwindow.cpp')
-rw-r--r--examples/speech/hello_speak/mainwindow.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/examples/speech/hello_speak/mainwindow.cpp b/examples/speech/hello_speak/mainwindow.cpp
index 2a2ca62..ae383e6 100644
--- a/examples/speech/hello_speak/mainwindow.cpp
+++ b/examples/speech/hello_speak/mainwindow.cpp
@@ -103,8 +103,11 @@ void MainWindow::stateChanged(QTextToSpeech::State state)
{
if (state == QTextToSpeech::Speaking) {
ui.statusbar->showMessage("Speech started...");
- } else if (state == QTextToSpeech::Ready)
+ } else if (state == QTextToSpeech::Ready) {
ui.statusbar->showMessage("Speech stopped...", 2000);
+ if (!m_localesQueried)
+ queryLocales();
+ }
else if (state == QTextToSpeech::Paused)
ui.statusbar->showMessage("Speech paused...");
else
@@ -117,12 +120,19 @@ void MainWindow::stateChanged(QTextToSpeech::State state)
void MainWindow::engineSelected(int index)
{
+ m_localesQueried = false;
QString engineName = ui.engine->itemData(index).toString();
delete m_speech;
if (engineName == "default")
m_speech = new QTextToSpeech(this);
else
m_speech = new QTextToSpeech(engineName, this);
+
+ connect(m_speech, &QTextToSpeech::stateChanged, this, &MainWindow::stateChanged);
+}
+
+void MainWindow::queryLocales()
+{
disconnect(ui.language, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &MainWindow::languageSelected);
ui.language->clear();
// Populate the languages combobox before connecting its signal.
@@ -144,11 +154,11 @@ void MainWindow::engineSelected(int index)
connect(ui.pauseButton, &QPushButton::clicked, m_speech, &QTextToSpeech::pause);
connect(ui.resumeButton, &QPushButton::clicked, m_speech, &QTextToSpeech::resume);
- connect(m_speech, &QTextToSpeech::stateChanged, this, &MainWindow::stateChanged);
connect(m_speech, &QTextToSpeech::localeChanged, this, &MainWindow::localeChanged);
connect(ui.language, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &MainWindow::languageSelected);
localeChanged(current);
+ m_localesQueried = true;
}
void MainWindow::languageSelected(int language)