c++ - 基于 Qt::ApplicationState 暂停 Qt 场景图渲染
问题描述
我正在尝试在 android 上的 Qt 应用程序中暂停渲染。初始状态更改后,应用程序被卡住,因为没有更新到达连接。
QScopedPointer<QQuickWindow> window ...
QSemaphore renderSemaphore(1);
bool releaseOnRender {};
QObject::connect(window.data(), &QQuickWindow::beforeRendering,
qApp, [&] {
releaseOnRender = renderSemaphore.tryAcquire(1, -1);
}, Qt::DirectConnection);
QObject::connect(window.data(), &QQuickWindow::afterRendering,
qApp, [&] {
if (releaseOnRender) {
renderSemaphore.release(1);
}
}, Qt::DirectConnection);
Qt::ApplicationState prevApplicationState = Qt::ApplicationState::ApplicationActive;
QObject::connect(qApp, &QGuiApplication::applicationStateChanged,
qApp, [&] (Qt::ApplicationState state) {
qDebug() << "Changed state to" << state;
if (state != prevApplicationState) {
if (state == Qt::ApplicationState::ApplicationSuspended) {
renderSemaphore.acquire(1);
qDebug() << "Freezing render";
} else {
renderSemaphore.release(1);
qDebug() << "Releasing render";
}
prevApplicationState = state;
}
}, Qt::DirectConnection);
我的实施源于对相关问题的建议。
有没有机会实现这一目标?也许使用不同的方法?
解决方案
推荐阅读
- java - 如何在不同的 SQL 查询中使用相同的 Java 类
- c++ - 我正在尝试在 C++ 上制作石头、纸、剪刀游戏,需要一些建议
- javascript - 如何将单词变成整数
- bash - 从 bash 脚本调用 matlab
- jquery - 如何压缩多个jquery if语句
- python - 尝试生成 n 个随机数,得出一个固定的总和
- c# - 取消 C# 异步函数
- ruby-on-rails - 使用 Clearance gem 的 Rails API 模式问题?
- javascript - 复选框违反数据验证规则
- android - ScrollView 在 android studio 中不能与 GridLayout 一起使用