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(); }
-
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"; }
-
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"; }
-
@mosleim What is the error message when your app crashes? sigsegv? Something else? Do you have stack trace? Did you try to debug your app? Is it always the same image causing the crash?
-
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 ?