PhoneConnectEngine::PhoneConnectEngine(QObject *parent) :
QThread(parent)
{
moveToThread(this);
qRegisterMetaType<QByteArray>("TDeviceConnectState");
connect(this, SIGNAL(stateChanged(TDeviceConnectState)), this, SLOT(onStateChanged(TDeviceConnectState)),Qt::QueuedConnection);
m_deviceState = ENotConnected;
start();
}
....
m_phoneConnectEngine = new PhoneConnectEngine();
connect(m_phoneConnectEngine, SIGNAL(stateChanged(TDeviceConnectState)), this, SLOT(onStateChanged(TDeviceConnectState)));//这里试图将状态信号不能成功发出来,debug出现segment fault,去掉这个connect,PhoneConnectEngine run正常,完全没有问题。
相关错误时的stack如下图片所示:
------解决方案--------------------
不建议LZ使用moveToThread(this),虽然说这种用法可以起作用。看下下面这篇博文吧。
http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/