小编Kyu*_*ark的帖子

如何防止PyQt对象从不同的线程收集垃圾?

我正在使用Qt 4.7和PyQt 4.7来构建一个多线程GUI程序.我一直在仔细管理PyQt对象,以便它们保留在一个UI线程中以避免同步问题,并且通常没有问题.

但有时候,在从其他线程激活python垃圾收集器的那一刻,Qt对象的析构函数就在那里被调用,并且以下断言从Qt内部失败.

我甚至可以为调试版本定义QT_NO_DEBUG,它应该没问题,因为收集的对象几乎不会导致同步问题.但是,我认为关闭其他调试消息并不是一个好主意.我该如何防止这种情况发生?

#if !defined (QT_NO_DEBUG) || defined (QT_MAC_FRAMEWORK_BUILD)
void QCoreApplicationPrivate::checkReceiverThread(QObject *receiver)
{
    QThread *currentThread = QThread::currentThread();
    QThread *thr = receiver->thread();
    Q_ASSERT_X(currentThread == thr || !thr,
               "QCoreApplication::sendEvent",
               QString::fromLatin1("Cannot send events to objects owned by a different thread. "
                                   "Current thread %1. Receiver '%2' (of type '%3') was created in thread %4")
               .arg(QString::number((quintptr) currentThread, 16))
               .arg(receiver->objectName())
               .arg(QLatin1String(receiver->metaObject()->className()))
               .arg(QString::number((quintptr) thr, 16))
               .toLocal8Bit().data());
    Q_UNUSED(currentThread);
    Q_UNUSED(thr);
}
#elif defined(Q_OS_SYMBIAN) && defined (QT_NO_DEBUG) 

python qt multithreading garbage-collection pyqt

4
推荐指数
2
解决办法
1589
查看次数

标签 统计

garbage-collection ×1

multithreading ×1

pyqt ×1

python ×1

qt ×1