[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();
    m_btn_cont->setEnabled(true);
    //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

    @void AjoutDefaut::startBorderDetect()
    {
    auto n = m_currentAnomaly->width(); CRASH HERE
    //m_dragWidgetCible->border_detect(*m_currentAnomaly);
    }@

    Thank you.


  • Lifetime Qt Champion

    Hi,

    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.


  • Lifetime Qt Champion

    Also

    @void AjoutDefaut::(const QImage& image)@

    use const references, no need copy the data multiple times



  • Ok thank's.


  • Lifetime Qt Champion

    Since your problem is solved, please update the thread title prepending [solved] so other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.