Qt错误:'(QMessageBox::Icon)1u' cannot be used as a function

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

程序代码如下:

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,才是静态成员函数。

做个广告:

 http://shop66019318.taobao.com/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值