简体   繁体   English

Qt应用程序界面冻结

[英]Qt application interface freeze

I'm experiencing some problems with my embedded application. 我的嵌入式应用程序遇到了一些问题。 It is a page that contains a QTimeEdit that counts the time each second, some checkboxes and some QLineEdit s that refresh each second. 它是一个包含QTimeEdit的页面,该QTimeEdit计算时间,一些复选框和一些QLineEdit每秒刷新一次。

After some minutes of working, I see a freeze of interface, even if the application is still running. 经过几分钟的工作,即使应用程序仍在运行,我仍然看到界面冻结。 If a try to press buttons or checkboxes an access violation message appears: 如果尝试按按钮或复选框,则会显示访问冲突消息:

Exception 'Access Violation' (14): Thread-Id=05d80002(pth=8af6109c), Proc-Id=04a90002(pprc=91431714) 'nmb3.exe', VM-active=04a90002(pprc=91431714) 'nmb3.exe' PC=407ea307(qtgui4.dll+0x0005a307) RA=40d6c82c(qtgui4.dll+0x005dc82c) SP=01c1b928, BVA=00000004 异常'访问冲突'(14):线程ID = 05d80002(pth = 8af6109c),Proc-Id = 04a90002(pprc = 91431714)'nmb3.exe',VM-active = 04a90002(pprc = 91431714)'nmb3.exe 'PC = 407ea307(qtgui4.dll + 0x0005a307)RA = 40d6c82c(qtgui4.dll + 0x005dc82c)SP = 01c1b928,BVA = 00000004

The exception is related to qtgui4.dll . 该异常与qtgui4.dll有关。 I checked if a saturation of virtual memory occurs, but this is not the problem that causes the freeze. 我检查了是否发生了虚拟内存饱和,但这不是导致冻结的问题。

The freeze doesn't occur if I avoid to update the QTimeEdit , but I don't understand why. 如果我避免更新QTimeEdit ,则不会发生冻结,但是我不明白为什么。

You should move the timer into the mainwindow class, keeping the sensors handler in the separated thread. 您应该将计时器移到mainwindow类中,使传感器处理程序保持在单独的线程中。

The sensors handler should: 传感器处理程序应:

  • store the data 存储数据
  • emit a "data ready" signal to the window 向窗口发出“数据就绪”信号

Then the timer in the mainwindow, every second, will: 然后,主窗口中的计时器将每秒:

  • read the data from the sensors handler 从传感器处理程序读取数据
  • update the GUI 更新GUI

(make sure you are using thread-safe objects or, managing the critical sections) (确保您使用的是线程安全对象,或管理关键部分)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM