QT QPixmap加载图像失败
QT QPixmap load image defeat
qDebug() << QFileInfo(":/images/123.jpg").exists();
QPixmap myPix;
myPix.load(":/images/123.jpg");
if(myPix.isNull())
{
qDebug() << "Failed to load image" ;
}
true
Failed to load image
这是代码和输出。它困扰了我很多时间。
看起来资源已损坏...无法加载。
您应该验证资源是否已正确加载:
if(myPix.load(":/images/123.jpg"))
{
....
}
如文档中所述 (https://doc.qt.io/qt-5/qpixmap.html#load):
Loads a pixmap from the file with the given fileName. Returns true if the pixmap was successfully loaded; otherwise invalidates the pixmap and returns false.
qDebug() << QFileInfo(":/images/123.jpg").exists();
QPixmap myPix;
myPix.load(":/images/123.jpg");
if(myPix.isNull())
{
qDebug() << "Failed to load image" ;
}
true
Failed to load image
这是代码和输出。它困扰了我很多时间。
看起来资源已损坏...无法加载。
您应该验证资源是否已正确加载:
if(myPix.load(":/images/123.jpg"))
{
....
}
如文档中所述 (https://doc.qt.io/qt-5/qpixmap.html#load):
Loads a pixmap from the file with the given fileName. Returns true if the pixmap was successfully loaded; otherwise invalidates the pixmap and returns false.