请高手分析一下QImageReaderPrivate::initHandler() 返回false的原因
/*!
\internal
*/
bool QImageReaderPrivate::initHandler()
{
// check some preconditions
if (!device || (!deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly))) {
imageReaderError = QImageReader::DeviceError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Invalid device"));
return false;
}
// probe the file extension
if (deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly) && autoDetectImageFormat) {
QList<QByteArray> extensions = QImageReader::supportedImageFormats();
if (!format.isEmpty()) {
// Try the most probable extension first
int currentFormatIndex = extensions.indexOf(format.toLower());
if (currentFormatIndex > 0)
extensions.swap(0, currentFormatIndex);
}
int currentExtension = 0;
QFile *file = static_cast<QFile *>(device);
QString fileName = file->fileName();
do {
file->setFileName(fileName + QLatin1Char('.')
+ QString::fromLatin1(extensions.at(currentExtension++).constData()));
file->open(QIODevice::ReadOnly);
} while (!file->isOpen() && currentExtension < extensions.size());
if (!device->isOpen()) {
imageReaderError = QImageReader::FileNotFoundError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "File not found"));
file->setFileName(fileName); // restore the old file name
return false;
}
}
// assign a handler
if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
imageReaderError = QImageReader::UnsupportedFormatError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format"));
return false;
}
return true;
}
QImageReader
[解决办法]
朋友,你只有把你的问题写出来,我们才好帮你啊
[解决办法]
设备都打不开,或者没有就绪,当然要返回false了。
最好看看插件之类的装上了没有。