我的测试代码如下:
----------------------------例1-----------------------------
#include <QApplication>
#include <QLabel>
#include <QPixmap>
#include <QImage>
#include <QString>
int main(int argc,char *argv[])
{
QImage p("test.jpeg");
QApplication app(argc, argv);
if(!p.isNull())
{
QLabel *label = new QLabel("OK");
label->show();
return app.exec();
}
}
这样,无论if中的条件是!p.isNull()或者p.isNull(),都无法显示“OK”
-------------------------------例子2-----------------------------------
#include <QApplication>
#include <QLabel>
#include <QPixmap>
#include <QImage>
#include <QString>
int main(int argc,char *argv[])
{
QImage p("test.png");
QApplication app(argc, argv);
if(!p.isNull())
{
QLabel *label = new QLabel("OK");
label->show();
return app.exec();
}
}
这样,当if条件为!p.isNull(),则可以显示"OK",证明加载成功
--------------------------------
在论坛查找,说加载jpeg要先用QPixmap 然后转换才能用QImage加载。
于是,我修改代码
#include <QApplication>
#include <QLabel>
#include <QPixmap>
#include <QImage>
#include <QString>
int main(int argc,char *argv[])
{
QPixmap p("test.png"); //这里改用了QPixmap
QApplication app(argc, argv);
if(!p.isNull())
{
QLabel *label = new QLabel("OK");
label->show();
return app.exec();
}
}
结果,依然是无法加载!!
我又搜索了一下,有的说插件问题,但我打开Qt-4.4.3/plugins/imagefomats目录下,
看到有libqjpeg.so
那请问我应该怎么加载jpeg图片呢??
谢谢!!
[ 此帖被codero在2009-03-03 15:04重新编辑 ]