本文整理汇总了C++中QThreadData::ref方法的典型用法代码示例。如果您正苦于以下问题:C++ QThreadData::ref方法的具体用法?C++ QThreadData::ref怎么用?C++ QThreadData::ref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QThreadData
的用法示例。
在下文中一共展示了QThreadData::ref方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createEventDispatcher
void *QThreadPrivate::start(void *arg)
{
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
pthread_cleanup_push(QThreadPrivate::finish, arg);
QThread *thr = reinterpret_cast<QThread *>(arg);
QThreadData *data = QThreadData::get2(thr);
pthread_once(¤t_thread_data_once, create_current_thread_data_key);
pthread_setspecific(current_thread_data_key, data);
data->ref();
data->quitNow = false;
// ### TODO: allow the user to create a custom event dispatcher
createEventDispatcher(data);
emit thr->started();
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_testcancel();
thr->run();
pthread_cleanup_pop(1);
return 0;
}
示例2: moveToThread
void QObject::moveToThread(QThread *targetThread)
{
if (m_threadData.load()->thread == targetThread) {
// object is already in this thread
return;
}
if (m_parent != 0) {
qWarning("QObject::moveToThread() Can not move an object with a parent");
return;
}
if (isWidgetType()) {
qWarning("QObject::moveToThread() Widgets can not be moved to a new thread");
return;
}
QThreadData *currentData = QThreadData::current();
QThreadData *targetData = targetThread ? QThreadData::get2(targetThread) : new QThreadData(0);
QThreadData *threadData = m_threadData.load();
if (threadData->thread == 0 && currentData == targetData) {
// exception: allow moving objects with no thread affinity to the current thread
currentData = threadData;
} else if (threadData != currentData) {
qWarning("QObject::moveToThread() Current thread (%p) is not the current object's thread (%p).\n"
"Can not move to target thread (%p)\n", currentData->thread, threadData->thread, targetData->thread);
#ifdef Q_WS_MAC
qWarning("Multiple libraries might be loaded in the same process. Verify all plugins are "
"linked with the correct binaries. Export DYLD_PRINT_LIBRARIES=1 and verify only one set of "
"binaries are being loaded.");
#endif
return;
}
// prepare to move
this->moveToThread_helper();
QOrderedMutexLocker locker(¤tData->postEventList.mutex, &targetData->postEventList.mutex);
// keep currentData alive
currentData->ref();
// move the object
this->setThreadData_helper(currentData, targetData);
locker.unlock();
currentData->deref();
}