遇到了同样的问题。
我有一个线程将数据加载到Model
. 完成后,我让线程发出信号DataLoadingDone
。这连接到过MainWindow
孔中的一个插槽,Qt::QueuedConnection
因此它是从 GuiThread 评估的。否则,我遇到了引发QBarSet
异常的插槽的问题。
MainWindow::MainWindow() {
this->chart = new QChart();
this->chartView = new QChartView(chart);
this->series = new QBarSeries();
this->mapper = new QHBarModelMapper(this);
this->connect(this->myThread, SIGNAL(DataLoadingDone()),
this, SLOT(MyThread_DataLoadingDone()),
Qt::QueuedConnection);
this->setWidget(this->chartView);
}
void MainWindow::MyThread_DataLoadingDone() {
mapper->setFirstBarSetRow(0);
mapper->setLastBarSetRow(0);
mapper->setFirstColumn(0);
mapper->setColumnCount(this->model->columnCount());
mapper->setSeries(series);
mapper->setModel(this->model);
//only add at the first time
//if we add this every time something goes wrong and
// multiple bars are displayed behind each other
if (this->chart->series().count() == 0) {
this->chart->addSeries(series);
this->chart->createDefaultAxes();
}
}