我在将 QImage 发送到 GUI 线程时遇到问题:
这是我在子线程中的代码:
QSize size = ui->label_2->size();
size=ui->label_2->size();
QImage pic(size.width(),size.height(),QImage::Format_ARGB32_Premultiplied);
pic.fill(Qt::transparent);
QPainter painter(&pic);
for (unsigned int i=0; i < wayVector.size(); i++){
double *x = new double[wayVector[i].refs.size()];
double *y = new double[wayVector[i].refs.size()];
for (unsigned int j=0; j<wayVector[i].refs.size(); j++){
x[j]=nodeHash[wayVector[i].refs[j]].lon;
y[j]=nodeHash[wayVector[i].refs[j]].lat;
}
for (unsigned int j=0; j<wayVector[i].refs.size()-1;j++){
painter.setPen(Qt::green);
painter.drawLine(size.width()*x[j]/(maxlon-minlon),
size.height()*maxlat/(maxlat-minlat)-size.height()*y[j]/(maxlat-minlat),
size.width()*x[j+1]/(maxlon-minlon),
size.height()*maxlat/(maxlat-minlat)-size.height()*y[j+1]/(maxlat-minlat));
}
}
emit sendPixmap(pic);
这是信号/插槽连接:
connect(this,SIGNAL(sendPixmap(QImage)),this,SLOT(setImage(QImage)));
这是插槽的定义:
void MainWindow::setImage(QImage img){
ui->label_2->setPixmap(QPixmap::fromImage(img));
}
但是什么也没发生,标签清除并且没有图像出现。我做错了什么?等待您的帮助:(