对Qt TextToSpeech
Qt 6 是我们努力使框架更高效、更易用的结果。
我们努力在每个版本中保持所有公共 API 的二进制和源代码兼容性。但为了使 Qt 成为更好的框架,有些改动是不可避免的。
在本主题中,我们总结了 Qt TextToSpeech中的更改,并提供处理这些更改的指导。
可用引擎
Qt 5 中可用的所有引擎在 Qt 6.4 中同样可用。有关 Qt 6.4 中可用引擎的完整列表,请参阅Qt TextToSpeech Engines。
引擎现在可以接收额外的配置参数。在构建QTextToSpeech 实例时,可通过QVariantMap 传递特定于引擎的键/值对。
API 变化
该 Qt TextToSpeech模块进行了一些基本的合并和清理。只需极少的移植工作即可切换到 Qt 6。
QTextToSpeech 类
QTextToSpeech::State 枚举值BackendError
已更名为Error
。详细的错误信息可通过QTextToSpeech::errorReason() 和QTextToSpeech::errorString() 获取。
新的engine 属性允许在初始化的QTextToSpeech 对象上更改引擎。
pause 和QTextToSpeech::stop 插槽使用QTextToSpeech::BoundaryHint 枚举值。如果信号有以前忽略的参数,这将破坏使用 PMF 语法的信号/槽连接的编译:
connect(stopButton, &QPushButton, tts, &QTextToSpeech::stop);
要么连接到不带参数的信号,要么使用 lambda 并明确调用相应的插槽方法:
connect(stopButton, &QPushButton, tts, [tts]{ tts->stop(); });
QVoice 类
使用QVoice 类的现有代码仍可像以前一样工作。QVoice 对象现在可通过QDataStream 进行序列化。
QTextToSpeechEngine 和 QTextToSpeechPlugin 类
这些类已从公共 API 中删除。它们仍然存在,并被可用的引擎实现所使用,但它们不属于文档化和受支持的 API 的一部分,而且很可能在未来的版本中发生变化。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.