【发布时间】:2011-07-11 19:32:48
【问题描述】:
WMIQuery::wmiquery(WMI::WMITable* table, const QString& query, WMI::ProgressIndicator* progressIndicator)
这是函数签名。我通过QtConcurrent::run调用它
QFuture<quint32> future = QtConcurrent::run(WMI::WMIQuery::wmiquery, _table, query);
架构非常简单。
查询将返回的预期行数是已知的。
查询并行运行,并在每条记录上提取一行添加到table: WMI::WMITable*
WMI::WMITable 是一个简单的 QObject 表数据结构。
它在添加行时发出rowsAboutToBeInserted(QModelIndex, int, int) 和rowsInserted(QModelIndex, int, int)。
另一方面,ProgressIndicator 在主线程上实例化,table 被传递给它的 ctor。它获取从WMI::WMIQuery::wmiquery() 到ProgressIndicator::setRecordCount(quint64 count) 的预期总行数。
它有一个插槽rowAdded(),它通过做一些简单的数学计算得出100分的进度。在它的ctor中它连接了
connect(_table, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowAdded()));
我的想法。由于WMI::WMIQuery::wmiquery() 我在不同的线程(QThreadPool)上运行,此连接是跨线程排队连接。我说的对吗?
我在运行时收到以下错误
QObject::connect: 无法将“QModelIndex”类型的参数排队
(确保使用 qRegisterMetaType() 注册 'QModelIndex'。)
我该怎么办?因为我的SLOT(rowAdded()) 不需要SIGNAL(rowsInserted(QModelIndex,int,int)) 的3 个参数,我是否应该发出另一个信号,如rowInserted() 并在我发出rowsInserted(QModelIndex,int,int) 时发出它,并使用这个SIGNAL 而不是这个连接
你可能会问为什么我在表数据结构中使用类似rowsInserted(QModelIndex,int,int) 的信号模型。因为我也有一个连接到这个表的模型。这也将逐行更新。但是我认为这在这方面是不重要的。
【问题讨论】:
标签: qt threadpool signals-slots qmodelindex