liuyanghejerry
17th May 2011, 15:55
I have a piece of code like pseudo code below:
class ImIncludeTable{
mMainTable = new QTableWidget(30,4,this);//This class contains a QTableWidget
....
mAction1 = new QAction(tr("Book/Cancel"),mMainTable);
....
mMainTable->addAction(mAction1);//add an action to this QTableWidget
mMainTable->setContextMenuPolicy(Qt::ActionsContextMenu);
....
connect(mAction1,SIGNAL(trigger()),this,SLOT(OpenA Dialog));//Open a Dialog, like a Qt::ApplicationModal Dialog while the action triggered
....
if(OpenADialog->result()) delete this;//if the dialog says true, the object will be called to delete itself. It's not a direct call, but a call by other class.
}
When the code run to the delete object line, a runtime error pops up.
But if I don't use a right-clicked context, everything is fine.
So, will QTableWidget delete its QMenu twice?
Or, because the QMenu is deleted by itself(when disappearing) after the delete object call, so it is deleted twice?
class ImIncludeTable{
mMainTable = new QTableWidget(30,4,this);//This class contains a QTableWidget
....
mAction1 = new QAction(tr("Book/Cancel"),mMainTable);
....
mMainTable->addAction(mAction1);//add an action to this QTableWidget
mMainTable->setContextMenuPolicy(Qt::ActionsContextMenu);
....
connect(mAction1,SIGNAL(trigger()),this,SLOT(OpenA Dialog));//Open a Dialog, like a Qt::ApplicationModal Dialog while the action triggered
....
if(OpenADialog->result()) delete this;//if the dialog says true, the object will be called to delete itself. It's not a direct call, but a call by other class.
}
When the code run to the delete object line, a runtime error pops up.
But if I don't use a right-clicked context, everything is fine.
So, will QTableWidget delete its QMenu twice?
Or, because the QMenu is deleted by itself(when disappearing) after the delete object call, so it is deleted twice?