Qt - 工作线程上的神秘段错误 [英] Qt - Mysterious segfaults on worker thread

查看:52
本文介绍了Qt - 工作线程上的神秘段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个工作线程上实例化 QSystemDeviceInfo,但它会导致段错误.

I'm instantiating QSystemDeviceInfo on a worker thread, but it causes a segfault.

int BatteryInfo::getLevel() {
   QSystemDeviceInfo sysDevInfo; //segfault happens when I step on to this line
   return sysDevInfo.batteryLevel();
}

该类是线程安全的,还是问题出在其他地方?

Is the class thread-safe, or does the problem lie elsewhere?

通过进一步调试,我还注意到本机 Symbian 也会调用 segfault.

最好的问候

推荐答案

我和我的朋友在 Symbian Qt Mobilty 1.0 上也发现了这个问题.他报告了一个问题QtMobility 从多个线程访问.正如问题描述中所说认为这可能是由于第一次创建 QSystemDeviceInfo/QSystemNetworkInfo 时创建了一些静态成员..

Me and my friend found this issue as well on Symbian Qt Mobilty 1.0. He reported an issue QtMobility access from multiple threads. As it says in the issue description Think this could be due to that some static members are created first time the QSystemDeviceInfo/QSystemNetworkInfo is created..

如果您使用 Qt Mobility 1.2 或仅从一个线程访问 QSystemDeviceInfo,则是其他问题.

If you are using Qt Mobility 1.2 or only accessing QSystemDeviceInfo from one thread it's some other issue.

我们的一种解决方法是确保我们首先在主线程中创建了一个 QSystemDeviceInfo 对象,但随后我们遇到了一些无法获取所有信号的问题.

One workaround for us was to make sure we created a QSystemDeviceInfo object in our main thread first but then we had some problems with not getting all signals.

这篇关于Qt - 工作线程上的神秘段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆