Qt Multimedia 在 Windows 上
本页面讨论在 Windows 上使用Qt Multimedia 时需要注意的事项。
关于 COM 的说明
Qt Multimedia 使用来自 Windows 平台的 COM API。这要求在访问Qt Multimedia API 的线程上初始化 COM。尽管Qt Multimedia API 会根据需要自动初始化 COM,但我们建议在应用程序启动时,从主线程初始化QGuiApplication 实例,然后再调用任何Qt Multimedia API。 这可确保在从任何线程调用Qt Multimedia API 之前,主单线程公寓(main STA)已完成初始化。同时,这也保证在所有其他公寓关闭之前,主 STA 不会被解除初始化状态。
Qt Multimedia 需要 COM 的 API 会通过调用CoInitializeEx(nullptr, COINIT_APARTMENT_THREADED) 将线程初始化为单线程公寓,并且在线程退出之前不会调用CoUninitialize 。这同样适用于主应用程序线程,在该线程中,CoUninitialize 会在静态变量销毁期间被调用。
© 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.