c++ - QPixmap load segmentation fault -
i creating qt console application on windows 7. using qt 5.3. , have error make me frustration because of it. check on stackoverflow, no answers me.
my problem when creating qpixmap got error segmentation fault , don't have other error information it.
here code :
qstring filepath = (directory + xmlreader.attributes().value("relativepath").tostring()); qfile _file(filepath); if (!_file.exists()) { qwarning() << "error : file " << filepath << " 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 last line of code generate segmentation fault error on machine. there can debug error?
update : have code on qpixmap, lead same segmentation fault.
code 1 :
qstring filepath = (directory + xmlreader.attributes().value("relativepath").tostring()); qfile _file(filepath); if (!_file.exists()) { qwarning() << "error : file " << filepath << " 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 << " 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 << " not exist"; return false; } qpixmap mainpixmap; if(_file.open(qfile::readonly)) { mainpixmap.loadfromdata(_file.readall()); //segmentation fault here }
finally have figured out problem. problem need have qguiapplication instance before using qpixmap.
on console application has qcoreapplication root qapplication, when want use qpixmap need change qguiapplication on main.cpp.
hope others. :)
Comments
Post a Comment