我已经完全尝试了我所知道的一切,而且我已经得出结论,这个问题已经过去了。我尝试过运行repaint(),update()和this-> update();以及我能想到的其他一切。 Pixmap在函数外部(在构造函数中)工作,但不在函数内部工作。这是代码(仅粘贴相关内容,如果您想要更多内容,请说明):
myWidget.h
#define NUM_POINTERS 10
QLabel* pointerArray[NUM_POINTERS];
QPixmap circle;
QPixmap* triangle;
QPixmap* whitex;
int activePointer;
myWidget.cpp
activePointer = 0;
QPixmap circle (":/Resources/greencircle.png");
this->whitex = new QPixmap(":/Resources/white_x.png");
this->triangle = new QPixmap(":/Resources/redtriangle.png");
//create an array of pointers to the label1-10 objects
pointerArray[0] = ui->label1;
pointerArray[1] = ui->label2;
pointerArray[2] = ui->label3;
...
pointerArray[9] = ui->label10;
for (int i = 0;i < 10; i++)
{
pointerArray[i]->setPixmap(circle);
}
void myWidget::changeImage()
{
updatesEnabled();
if (activePointer < 10){
pointerArray[activePointer]->setPixmap(*this->whitex);
activePointer++;
update();
}
else{
printf("end of array\n");
fflush(stdout);
}
}
我在我想要的地方打印了一排圆圈,但我没有得到任何白色的X.像素图更改为whitex,但不会更新。它不会崩溃,它会继续添加到activePointer,直到数组结束。
提前致谢。
快速编辑:我尝试过pointerArray [activePointer] - &gt; update();没有运气。