程序代码如下:
void MainWindow::on_commandLinkButton_clicked()
{
if(this->currentImage == 4)
this->currentImage = 0;
else
this->currentImage ++;//更新当前图片
QString fileName = list.at(this->currentImage);
if(!fileName.isEmpty()) //图片是否存在
{
QImage image(fileName);
if(image.isNull())
{
QMessageBox::Information(this,tr("Image Viewer"),tr("Cannot load %1.").arg(fileName));
return;
}
ui->imageLabel->setPixmap(QPixmap::fromImage(image)); //用图片填充imageLabel
}
}
编译报错:
/home/xiaofeng/qt/CommandLinkButton/ComLinButton/mainwindow.cpp:48:
错误:'(QMessageBox::Icon)1u' cannot be used as a function
进过分析发现:
QMessageBox::Information(this,tr("Image Viewer"),tr("Cannot load %1.").arg(fileName));
中的,Information有问题,应该是information,没注意首字母大小写,QMessageBox::information,才是静态成员函数。
做个广告:

本文讨论了Qt程序中QMessageBox使用时的一个常见错误,并提供了修正方法。同时,文章包含了一个链接到淘宝店铺进行产品推广。
1659

被折叠的 条评论
为什么被折叠?



