PDA

View Full Version : Unhandle Exception



samar
9th June 2011, 19:24
hi all,
I am working on Visual studio C++ with Qt4.7.
I have a class and I made a button in the toolBar and connect it to a method. and connect the method to another class. and when I debug, the error found is: "Unhandled exception at 0x505b3f4f (QtCored4.dll) in zsensormonitor.exe: 0xC0000005: Access violation writing location 0xcccccccc."

mainwindow.cpp


Node *sNode;

work=new QPushButton(tr("please"));
connect(work,SIGNAL(clicked()),this,SLOT(showC())) ;

void MainWindow::showC()
{
find_Addr();
}
void MainWindow::find_Addr()
{
this->sNode->showB();
}

node.cpp

static QList <QString> list;

void Node::showB()
{
QMessageBox m;
QPushButton *b;
QPushButton *k;

b=m.addButton(tr("Ok"),QMessageBox::AcceptRole);
k=m.addButton(tr("Cancel"),QMessageBox::AcceptRole);

for(int i=0; i<=list.size(); i++)
{

list << Address;

m.setText(list[i]);

m.exec();
}
}

please anyone help me :)

mattc
9th June 2011, 20:58
Looks like you are dereferencing an uninitialized pointer somewhere (0xCCCCCCCC is a bit pattern VS writes on uninitialized memory in debug mode).

Is sNode properly initialized in find_Addr()?

Santosh Reddy
9th June 2011, 23:22
You have 2 bugs in you code.

[1]. Infinite Loop

for(int i=0; i<=list.size(); i++) //this is an infinite loop, and hence the application might be crashing (Exception) after a while
{
list << Address; // This will increase the list size every loop
...
}

[2]. Loop exit condition should be i < list.size() (not i <= list.size()), as the index starts from 0