QSocketNotifier: Socket notifiers cannot be enabled or disabled from another ...
QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread主线程中不能调用网络请求,把网络请求放线程中。
跟单例的实现方法也有关系,如下两个,上面会报这个错,下面正常 static QSharedPointer<QControlSo>& instance()
{
if (m_pInstance.isNull())
{
QMutexLocker mutexLocker(&m_Mutex);
if (m_pInstance.isNull())
m_pInstance = QSharedPointer<QControlSo>(new QControlSo());
}
return m_pInstance;
}下面的正确static QControlSo &instance(void)
{
#ifdef Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE
if(!QAtomicPointer<QControlSo>::isTestAndSetNative())//运行时进行检测
qDebug() << "Error: don's support TestAndSetNative!!!!!!";
#endif
//双重检测加锁
if(m_pInstance.testAndSetOrdered(0,0)){
QMutexLocker locker(&m_Mutex);
m_pInstance.testAndSetOrdered(0, new QControlSo);
}
return * m_pInstance;
}
private://下与上相同
QControlSo();
QControlSo(const QControlSo &);
QControlSo & operator=(const QControlSo &);
QReadWriteLock internalMutex;
static QMutex m_Mutex;
static QAtomicPointer<QControlSo> m_pInstance;
QMutex QControlSo::m_Mutex;
QAtomicPointer<QControlSo> QControlSo::m_pInstance;
页:
[1]