PDA

View Full Version : Crashing problem while checking for QCheckBox is CHECKED/UNCHECKED



Channareddy
9th June 2011, 07:10
hi,
Here is my code for checking wheater the QCheckBox is checked or not.
I don't want to use SIGNALS & SLOTS.Give me some solution which has no SIGNALS & SLOT coz using SIGNALS & SLOTS its too lengthy for my code as i have to check 25 checkBoxes.So please keep it short n sweet..:)

QCheckBox *floor1 = new QCheckBox("Floor 1",this);
floor1->setCheckable(1);

if(floor1->isChecked()) //the code is crashing at this line
{
if(this->door11->isChecked())
line.append("Door 11");
}

Also i tried with below code but same problem.

if(floor1->checkState()==Qt::Checked) //the code is crashing at this line
{
if(this->door11->isChecked())
line.append("Door 11");
}

Please help me to overcome this issue ASAP...:(

ChrisW67
9th June 2011, 07:24
The most likely problem is that floor1 is either NULL or pointing at a no-longer-valid location. What is the value of floor1 at the line it crashes?

I can only assume that the scope in which:


QCheckBox *floor1 = new QCheckBox("Floor 1",this);
floor1->setCheckable(1); // unnecessary, check boxes are checkable by default

occurs, and the remainder occurs are not the same or the crash would occur at line 2.

Santosh Reddy
9th June 2011, 07:24
QCheckBox *floor1 = new QCheckBox("Floor 1",this);
floor1->setCheckable(1);

//make sure floor1 is properly allocated, are you sure the above new statement is called before this?
if(floor1->isChecked()) //the code is crashing at this line
{
if(this->door11->isChecked())
line.append("Door 11");
}

Channareddy
9th June 2011, 13:33
Thank you..:)
From next time i will follow code posting guidelines Chris..Thanks for the reply..:)

Thank you..:) i got it done..:)