Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions
[solved]problem with variable member value and signals and slots connection
Hello, I have these two slots
@void AjoutDefaut::beginProcess(QImage image)
m_currentAnomaly = ℑ
auto n = m_currentAnomaly->width();
//QImage currentImage = *(m_dragWidgetCible->m_currentAnomaly);
connect(m_btn_cont, &QPushButton::clicked, this, &AjoutDefaut::startBorderDetect);
m_currentAnomaly is a member variable of AjoutDefaut.
m_currentNnomaly = &image works good (m_currentAnomaly is not NULL), but in the following slot, after connection with button click signal, compilater says that m_currentAnomaly points to NULL. I don't know what is the reason
auto n = m_currentAnomaly->width(); CRASH HERE
m_currentAnomaly points to an invalid memory location. You are giving it the address of "image" which is only valid the time of beginProcess.
Just use a QImage, it's an implicitly shared class.
I replaced all variable points to QImage to QImage, It works now,
Thank you for help SGaist.
@void AjoutDefaut::(const QImage& image)@
use const references, no need copy the data multiple times
Since your problem is solved, please update the thread title prepending [solved] so other forum users may know a solution has been found :)