QPixmap::fromImage(img) sometime crash.
-
this is my slot function. the slot is connected to signal from other thread. this function sometime work, sometime crash. when crash, "ui_start3" never printed. I think QPixmap::fromImage(img); is the problem. and try cath is not work.
in spesific state, when i produce a new window, the program usally crash.
how to check the img object is valid or try the code is safe to run?
void MainWindow::updateUI(QImage img) { qDebug()<<"ui_start1"; if (!img.isNull()) { qDebug()<<"ui_start2"<<img.size(); try { QPixmap p = QPixmap::fromImage(img); qDebug()<<"ui_start3"; ui->lbl_image->setPixmap(p.scaled(ui->lbl_image->size(), Qt::IgnoreAspectRatio, Qt::FastTransformation)); qDebug()<<"ui_start4"; } catch (...) { } } qDebug()<<"ui_start5"; }
-
Is this work under single thread?Maybe it is a bug cause by multithread, like resource crash, or you manipulate pixmap/update gui in non gui thread.
Besides, I think it would be better to print out the error messages(although it do not work in your case)
catch(std::exception const &ex){ qDebug()<<ex.what(); }
-
@jsulm this is from "just in time debugger" of vs. in QtCreator not show an error. and Aplication is returned 0.
Unhandled exception at 0x02001A00 (Qt5Guid.dll) in AutoLogMetalDetector.exe: 0xC0000005: Access violation reading location 0x228B6030
-
Hi,
Can you show how your create the image that you pass to the function ?
Also, can you provide a stack trace of your application crash ?