I'm having a few problem with cleaning a stack of pointers. In the below the line with the delete crashes: "memory fault/segmentation fault".
std::stack<reports*> stack;
while(db.fetch())
{
reports* report = new report(db);
QThreadPool::globalInstance()->start(report);
stack.push(report);
}
while( QThreadPool::globalInstance()->activateThreadCount() != 0 );
while( !stack.empty() )
{
delete stack.top();
stack.pop();
}
The context of this code is I think not relevant. Except that: db is passed by reference to report constructor, which immediately copy the necessary current row data as non pointer members. Can somebody give me a hint ?
EDIT:
Self answer:
Ok I was touch by god lights just after writing my question.
by default
QThreadPool::globalInstance()->start(report);
will take ownership of the object. Adding the following line in the loop solves the problem:
report->setAutoDelete(false);
Or symply not cleaning up... myself and let Qt Do it.