目前,我在将 QVector 传递到线程之间时遇到一些麻烦。目前我有一个主线程(GUI-Thread)和一个频繁发出 QVector 数组的工作线程。在向量内直接发出数据之前看起来不错。接收者是主线程中的一个槽,但该槽接收到的数据是乱码。
这是我的代码的一些部分:
在工作线程中发出:
void Pipeline::process
{
QVector<float> buffer(w * h * d);
// filling the vector with RGB-Values
emit this->pushBuffer(buffer, w, h, d);
}
主线程中signal和slot的连接:
QObject::connect(this->_pipeline.data(), SIGNAL(pushBuffer(const QVector<float>, int, int, int)), this->ui->widgetFiltered, SLOT(setBuffer(const QVector<float>,int,int,int)));
主线程中的插槽:
void GLWidget::setBuffer(const QVector<float> buffer, int dataSizeX, int dataSizeY, int dataSizeZ)
{
// at this point the contents inside 'buffer' is garbled
}
线程是通过使用 QObject 的 moveToThread 来启动的QVector<float>
注册到元系统qRegisterMetaType< QVector<float> >("QVector<float>");
在主要方法中。
之后数据有可能丢失吗Pipeline::process
回报?我不确定里面的隐式共享是如何实现的QVector
在这种多线程情况下的行为。
任何帮助,将不胜感激。
问候
Wolf