Hello,

I have a question with the following piece of code that can be found here

Qt Code:
  1. QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor)
  2. {
  3. QList<QColor> colors;
  4. colors << Qt::black << Qt::white << Qt::red << Qt::blue << Qt::yellow;
  5. QStringList names;
  6. names << tr("black") << tr("white") << tr("red") << tr("blue")
  7. << tr("yellow");
  8.  
  9. QMenu *colorMenu = new QMenu(this);
  10. for (int i = 0; i < colors.count(); ++i) {
  11. QAction *action = new QAction(names.at(i), this);
  12. action->setData(colors.at(i));
  13. action->setIcon(createColorIcon(colors.at(i)));
  14. connect(action, SIGNAL(triggered()), this, slot);
  15. colorMenu->addAction(action);
  16. if (colors.at(i) == defaultColor)
  17. colorMenu->setDefaultAction(action);
  18. }
  19. return colorMenu;
  20. }
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