Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format)
- 
@Wenchi 
 So the trace shows you clicked a button and it called yourCFuncToolSlamWidget::on_btn_add_clicked(). At line #263 that callsQImageReader::read(). So let's see the code around (i.e. leading up to) that line #263. We are probably particularly interested in the lifetime of theQImageyou are using.@JonB 
 I have already uploaded the code of function
 void CFuncToolSlamWidget::on_btn_add_clicked()
 to the description of the question.
 And the crash line is
 qImaggbk = reader.read();
 Since the crash doesn't appear necessarily, I couldn't figure out why it crashed.
- 
@JonB 
 I have already uploaded the code of function
 void CFuncToolSlamWidget::on_btn_add_clicked()
 to the description of the question.
 And the crash line is
 qImaggbk = reader.read();
 Since the crash doesn't appear necessarily, I couldn't figure out why it crashed.@Wenchi 
 Then it looks likeQImageReader::read()does not like the content of the.pngfile you are trying to load. Does it happen depending on which file is chosen? Try the code with a specified filename in some standalone code outside of your project and see how it goes?
- 
Try to use another tool to load your image and see if the file is corrupt or has some other issues. It may be a good idea to check if read() fails or not all the time like the following: QImage icon(64, 64, QImage::Format_RGB32); QImageReader reader("icon_64x64.bmp"); if (reader.read(&icon)) { // Display icon }the sample code is from here: 
 https://doc.qt.io/qt-5/qimagereader.html#read-1
- 
@Wenchi 
 Then it looks likeQImageReader::read()does not like the content of the.pngfile you are trying to load. Does it happen depending on which file is chosen? Try the code with a specified filename in some standalone code outside of your project and see how it goes?
- 
Try to use another tool to load your image and see if the file is corrupt or has some other issues. It may be a good idea to check if read() fails or not all the time like the following: QImage icon(64, 64, QImage::Format_RGB32); QImageReader reader("icon_64x64.bmp"); if (reader.read(&icon)) { // Display icon }the sample code is from here: 
 https://doc.qt.io/qt-5/qimagereader.html#read-1@JoeCFD 
 Thank you for your reply!
 Using another tool to load image can be a way to avoid the crash, but in my situstion, the crash could appear not only inQImageReader.read()but also in several other code, such asQlist<MyWidget>.push_back()orQStackWidget.setCurrentIndex()and so on.
- 
@JoeCFD 
 Thank you for your reply!
 Using another tool to load image can be a way to avoid the crash, but in my situstion, the crash could appear not only inQImageReader.read()but also in several other code, such asQlist<MyWidget>.push_back()orQStackWidget.setCurrentIndex()and so on.@Wenchi said in Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format): the crash could appear not only in QImageReader.read() but also in several other code, such as Qlist<MyWidget>.push_back() or QStackWidget.setCurrentIndex() and so on. Then you should fix your code. 
- 
@Wenchi 
 How do you expect anybody to offer any further help, if your code is crashing in various places?
- 
@JonB 
 Although the code is crashing in various places, the crash point is always the same:QImageData * QImageData::create(const QSize &size, QImage::Format format) )by the way, I'm fired. ready to get a new start @Wenchi said in Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format): Although the code is crashing in various places, but the crash point is always the same: But that is likely --- or just as possible --- indicating you have a problem elsewhere which only shows up here, such as corrupted/misallocated memory? How else would you explain it "crashing" in e.g. QList<MyWidget>.push_back()?by the way, I'm fired. ready to get a new start I am sorry to hear that, good luck for future. 
 


