I am creating a Qt Console Application on windows 7. I am using Qt 5.3. And currently I have error that make me frustration because of it. Already check on the stackoverflow, but no answers help me.
My problem was when creating a Qpixmap I got error segmentation fault and I don't have any other error information about it.
Here my code :
QString filePath = (directory + xmlReader.attributes().value("relativepath").toString());
QFile _file(filePath);
if (!_file.exists())
{
qWarning() << "Error : file " << filePath << " does not exist";
return false;
}
QImageReader imageReader(filePath);
QImage mainImage = imageReader.read();
if(mainImage.isNull())
{
qWarning() << "Error read image : " << filePath;
qWarning() << imageReader.errorString();
return false;
}
QPixmap mainPixmap(QPixmap::fromImage(mainImage)); // Segmentation fault here
On the last line of those code that generate the segmentation fault error on my machine. Is there anything i can do to debug this error?
Update : I have some code on QPixmap, but it lead the same segmentation fault.
Code 1 :
QString filePath = (directory + xmlReader.attributes().value("relativepath").toString());
QFile _file(filePath);
if (!_file.exists())
{
qWarning() << "Error : file " << filePath << " does not exist";
return false;
}
QImageReader imageReader(filePath);
QImage mainImage = imageReader.read();
if(mainImage.isNull())
{
qWarning() << "Error read image : " << filePath;
qWarning() << imageReader.errorString();
return false;
}
QPixmap mainPixmap;
mainPixmap = QPixmap::fromImage(mainImage); // segmentation fault here
Code 2 :
QString filePath = (directory + xmlReader.attributes().value("relativepath").toString());
QFile _file(filePath);
if (!_file.exists())
{
qWarning() << "Error : file " << filePath << " does not exist";
return false;
}
QPixmap mainPixmap;
mainPixmap.load(filePath); // segmentation fault here
Code 3 :
QString filePath = (directory + xmlReader.attributes().value("relativepath").toString());
QFile _file(filePath);
if (!_file.exists())
{
qWarning() << "Error : file " << filePath << " does not exist";
return false;
}
QPixmap mainPixmap;
if(_file.open(QFile::ReadOnly))
{
mainPixmap.loadFromData(_file.readAll()); //segmentation fault here
}
QPixmap::fromImage(mainImage)
to a separate line so you can try to determine whether it's that code or theQPixmap
constructor.