|
|
Exactly. Just like Chris Burke pointed out :)
cesar del solar schrieb:
So in this case, I should do QMenu* contextMenu = new QMenu(this); ?
Thanks for your help,
Cesar
"Thomas Dähling" <t.daehling@xxxxxxxxxxxxxx> wrote in message
news:46672BB4.1020106@xxxxxxxxxxxxxxxxx
Hi cesar,
I had the very same doubts as you when I started working with Qt. But rest
yourself assured: Whenever Qt provides to option of setting a parent - set
it and you won't have to worry about memory. That's an easy rule of thumb
I stick to and I never had any problem with that.
Regards,
Thomas
cesar del solar schrieb:
So I thought about this while writing this code but this applies to other
things I've done with Qt. I have a table widget and would like a pop up
menu, so I reimplemented the appropriate function:
void contentsTableWidget::contextMenuEvent(QContextMenuEvent *event)
{
QMenu* contextMenu = new QMenu();
contextMenu->addAction("action 1");
contextMenu->addAction("action 2");
contextMenu->popup(event->globalPos());
connect(contextMenu, SIGNAL(triggered(QAction*)), this,
SLOT(menuItemClicked(QAction*)));
}
So when I right click the menu pops up, and clicking the actions works as
expected. But what happens to contextMenu? What if I keep right clicking,
do new QMenus keep being created and not destroyed? The way I dealt with
this before is to create the QMenu* in the class declaration, then inside
this function at the beginning do something like if (QMenu) delete QMenu,
etc etc. Is this necessary?
Cesar
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
|
|