[Qt-interest] dereferencing a pointer that is invalid

Jason H scorp1us at yahoo.com
Wed Nov 4 21:36:25 CET 2009


Would using QPointer<QClassName> help? (in the struct)

And I wonder if you need the & in &mc[i], because you'll already get the address by indexing into the array without referenceing a member, IIRC.



----- Original Message ----
From: navid navid <n_nnavid at yahoo.com>
To: qt-interest at trolltech.com
Sent: Wed, November 4, 2009 12:51:56 PM
Subject: [Qt-interest] dereferencing a pointer that is invalid

Hello,

i have encountered crash at

========================================
//header
struct MyControls
{
QComboBox * my_combobox;
QCheckBox * my_checkbox;
};

private:
QList<MyControls *> my_control_list;

//cpp
MyControls mc[8];
mc[0].my_combobox = ui->comboBox1;
....
mc[7].my_combobox = ui->comboBox8;
mc[0].my_checkbox = ui->checkBox1;
....
mc[7].my_checkbox = ui->checkBox8;
my_control_list.clear();
for (int i=0; i<8; i++) {my_control_list.insert(i,&mc[i]);} 

if(ui->checkBox1->isChecked())   return 1;
if (! my_control_list.at(0)->my_checkbox->isChecked())  //<- crash
return 0;

========================================

the crash  error is
myapplication.exe exited with code -1073741819   //(0xC0000005)
It looks like it is dereferencing a pointer that is invalid

//

also as a test
qDebug("list count = %d", my_control_list.count()); //list count = 8
if (! my_control_list.at(0)->my_checkbox->isChecked()) //<- crash

if (! my_control_list.at(1)->my_checkbox->isChecked()) //<- dont crash !

if (! my_control_list.at(2)->my_checkbox->isChecked()) //<- dont crash !

if (! my_control_list.at(7)->my_checkbox->isChecked()) //<- crash

if (! my_control_list.at(8)->my_checkbox->isChecked()) //<- crash 


regards
navid 


      
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest



      




More information about the Qt-interest-old mailing list