64位Win7中没有重绘QML视图(QDeclarativeItem中的update()被忽略)
我开发基于 QML 的 UI,其中一些元素是在 C++ 插件中实现的。 到目前为止,在 WinXP 32 位和 Win7 32 位中一切正常。上周我买了一台装有 Win7 64 位的新笔记本电脑,但我的代码在那里无法正常工作。启动应用程序几秒钟后表现良好,但随后视图突然停止重绘。 QML 启动的事件和对 QDeclarativeItem::update() 的插件调用都不起作用。在插件中,我 100% 确定 update() 被调用,但后来我知道,对重写 QGraphicsItem::paint() 的调用不会按预期发生。仅当窗口获得/失去焦点时,视图才会重绘。
我已经在运行 Win7 的桌面上快速验证了我的应用程序,没有出现任何问题。这让我怀疑 Windows 7 在我的笔记本电脑和其他计算机上请求窗口更新的方式有所不同,但我现在无法弄清楚其中的区别。
有人可以帮助我了解那里发生了什么吗?
提前致谢!
ps 不幸的是,我的原始模型没有表现出同样的问题,并且我无法共享生产代码。如果我能在找到实际解决方案之前找到一种在原型中重现此问题的方法,我将发布它。
I work on a QML-based UI where some elements are implemented in C++ plugin.
Everything worked fine so far in WinXP 32bit and Win7 32bit. Last week I got new laptop with Win7 64bit on board, and my code does not work properly there. Several seconds after start-up application behaves nicely, but then suddenly view stops redrawing. Neither QML-initiated events, nor plug-in calls to QDeclarativeItem::update() work. In plugin I am 100% sure that update() is called, but then I know, that calls to overriden QGraphicsItem::paint() do not happen as expected. The view only gets redrawn when window gets/looses focus.
I have quickly verified my application on a desktop running Win7 and had no problems there. This leads my to suspect that there is something different about how Windows 7 requests window update on my laptop and on other computers, however I am unable to figure out the difference right now.
Can someone help me out to understand what is going on there?
Thanks in advance!
p.s. Unfortunately my primitive mock-ups did not exhibit same problem, and I cannot share production code. If I will find a way to reproduce this problem in a prototype before actual solution will be found, I will post it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的问题的答案在于我最初在问题描述中忽略的东西。 QDeclarativeItem::update() 函数是从非 Qt 线程(当然不是 GUI 线程)调用的。 我通过 Qt 事件循环重新路由了调用,问题就消失了。
当时我使用的是 Qt 4.7/4.8,无法说明它在 Qt 5.x 中的表现如何。
The answer to my question lays in something I overlooked initially in my problem description. The QDeclarativeItem::update() function was called from a non-Qt thread (certainly not GUI thread). I re-routed the call through Qt event loop and the problem was gone.
I was on Qt 4.7/4.8 at that time and cannot say how it'd behave in Qt 5.x.
在 update() 调用之后添加 qapp->processEvents() ,它可能会起作用。
(我遇到过类似的问题,但它发生在所有平台上,希望这个解决方案对你有用)
Add a qapp->processEvents() after your update() call, it will probably work.
(I've come across a similar problem, but it happens on all platforms, hopefully this solution will work for you)