对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 的一部分,并且在未来的版本中可能会发生变化。
© 2026 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.