Hello,
I have a question with the following piece of code that can be found here
QMenu *MainWindow
::createColorMenu(const char *slot,
QColor defaultColor
) {
QList<QColor> colors;
colors << Qt::black << Qt::white << Qt::red << Qt::blue << Qt::yellow;
names << tr("black") << tr("white") << tr("red") << tr("blue")
<< tr("yellow");
for (int i = 0; i < colors.count(); ++i) {
action->setData(colors.at(i));
action->setIcon(createColorIcon(colors.at(i)));
connect(action, SIGNAL(triggered()), this, slot);
colorMenu->addAction(action);
if (colors.at(i) == defaultColor)
colorMenu->setDefaultAction(action);
}
return colorMenu;
}
QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor)
{
QList<QColor> colors;
colors << Qt::black << Qt::white << Qt::red << Qt::blue << Qt::yellow;
QStringList names;
names << tr("black") << tr("white") << tr("red") << tr("blue")
<< tr("yellow");
QMenu *colorMenu = new QMenu(this);
for (int i = 0; i < colors.count(); ++i) {
QAction *action = new QAction(names.at(i), this);
action->setData(colors.at(i));
action->setIcon(createColorIcon(colors.at(i)));
connect(action, SIGNAL(triggered()), this, slot);
colorMenu->addAction(action);
if (colors.at(i) == defaultColor)
colorMenu->setDefaultAction(action);
}
return colorMenu;
}
To copy to clipboard, switch view to plain text mode
According to the doc of QWidget::addAction(QAction *action), the ownership of action is not transferred to the QWidget, so I wonder if the memory of each action created are correctly released.
Thank you
Bookmarks