QLabel->setText() executed in a method causes program crash
Hi all,
I have an issue : When I want to execute a QLabel->setText() in the method "modifItem", it causes a program crash.
When I execute the lcd4->setText() in the constructor, it works, but not in the method "modifItem". --> lcd4 attribute seems to not be recognized even if lcd4 lights in red... It only happens with a QLabel or a QLCDNumber... I tried with a QTableWidgetItem->setItem() and it works well.
Caisse3.cpp
Code:
{
lcd4->setFixedSize(200,30);
layout5->addWidget(lcd4);
}
void Caisse3::modifItem(int row, int column)
{
QString nomArticle
=listBoissonsDenom
[row
];
lcd4->setText(nomArticle);
}
Caisse3.h
Code:
Q_OBJECT
public:
Caisse3();
public slots:
void modifItem(int row, int column)
private:
Thanks for your help.
Re: QLabel->setText() executed in a method causes program crash
In Caisse3::Caisse3(), you declare a local variable named lcd4, thus shadowing the lcd4 member of Caisse3. That member remains uninitialized (and therefore contains garbage), which causes a crash when you dereference it in Caisse3::modifItem().
Re: QLabel->setText() executed in a method causes program crash