Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format)
-
Look where in your code the crash comes from and post the code (not screenshot). Also make sure the QImage data is valid during the whole lifetime of the QImage object (which I doubt it is) - how do you create your QImage object?
wrote on 30 May 2022, 09:36 last edited by Wenchi@Christian-Ehrlicher @JonB
Thank you for your reply! I have updated the description of my question. Could you see whether the information is enough. Since I haven't read the book, <Advanced Windows Debugging>, I'm afraid I couldn't provide more debug infomation. -
@Christian-Ehrlicher @JonB
Thank you for your reply! I have updated the description of my question. Could you see whether the information is enough. Since I haven't read the book, <Advanced Windows Debugging>, I'm afraid I couldn't provide more debug infomation.wrote on 30 May 2022, 09:57 last edited by JonB@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 theQImage
you are using. -
@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 theQImage
you are using.wrote on 30 May 2022, 10:19 last edited by@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.wrote on 30 May 2022, 10:27 last edited by@Wenchi
Then it looks likeQImageReader::read()
does not like the content of the.png
file 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? -
wrote on 30 May 2022, 14:30 last edited by JoeCFD
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.png
file 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-1wrote on 31 May 2022, 03:48 last edited by@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.
-
wrote on 6 Jun 2022, 09:00 last edited by
please help!I'll lose my job if I can't fix this bug. crying
-
@Wenchi
How do you expect anybody to offer any further help, if your code is crashing in various places?wrote on 7 Jun 2022, 07:44 last edited by Wenchi 6 Aug 2022, 10:08@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
-
@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
wrote on 7 Jun 2022, 08:24 last edited by JonB 6 Jul 2022, 08:25@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.
13/15