[SOLVED] how to create a map of actions



  • Hi,
    I've got some problems creating a map of actions. In my code I've code something like the following:

    @QAction* actionUserManagement = new QAction( this );
    actionUserManagement->setText( tr("Manage users") );
    ...
    QAction& currentAction = *actionUserManagement;
    actionsMap->insert( QString("userview"), currentAction );@

    but this is not working, it seems the map is calling a QAction( QAction) constructor which is protected. How can I solve this?
    Thanks



  • What's "actionMap"? Why are you using a reference to a QAction?



  • You can not create a QMap<QAction>. Containers need their contents to be default constructable and copyable, and QAction does not satisfy those requirements (nor does any other QObject subclass). You can however create a QMap<QAction*> without problems, or even use one of the (shared) pointer classes in your map.



  • Thanks, using the QAction* works for me!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.