QAction Group Vs. Vector and Array



  • Hi,
    I am just wondering what is so special about QActionGroup. Why can't I use arrays? (when I did, I ran into Segmentation Faults) and/or vectors? Is QActionGroup a special class that cannot be initiated in the form of an array?

    Also;

    @
    ...
    ActionGroup->addAction(myAction);
    delete myAction;
    @

    is "myAction" now part of "ActionGroup" or is it now deleted? Does QActionGroup store action objects?

    Thanks!

    -Masoug



  • [quote author="masoug" date="1285381463"]Hi,
    I am just wondering what is so special about QActionGroup. ... Does QActionGroup store action objects?
    -Masoug[/quote]

    Have you checked the docs for QActionGroup in the Qt Assistant?

    @
    delete myAction;
    @

    If you want to remove myAction from the group, you should just use removeAction(myAction). Calling delete will "delete" myAction.



  • You can set a QActionGroup to be exclusive (only one action can be checked at a time). And more probably.



  • [quote author="chetankjain" date="1285398264"]
    If you want to remove myAction from the group, you should just use removeAction(myAction). Calling delete will "delete" myAction.[/quote]

    So if I just call @delete myAction;@ will I still be able to find "myAction" in "ActionGroup"? Or does "ActionGroup" have a copy of "myAction"?

    Thanks!

    -Masoug



  • [quote author="masoug" date="1285433909"]So if I just call @delete myAction;@ will I still be able to find "myAction" in "ActionGroup"? Or does "ActionGroup" have a copy of "myAction"?[/quote]

    Most certainly note. QActionGroups holds a pointer to myAction. When myAction is deleted, QActionGroup receives the destroyed() signal from myAction and removes it from it's internal list.

    Having said that, it's always better/safer to call deleteLater() on QObjects:

    @myAction->deleteLater()@



  • Okay, Thanks! I got it now.

    -Masoug



  • Oh, and by the way, why does the compiler complain about a segmentation fault when I:

    @

    myAction[index] = QAction(tr("HI"), this);

    @

    That was kinda the basis of my question...

    Thanks!

    -Masoug



  • masoug, what is myAction in this case and how have it been inititalized?



  • Do remember that QAction is a QObject and can therefore not be copied. If you want to pass the QAction around, use pointers to the thing.

    @myAction[index] = new QAction(tr("HI"), this);@

    Of course myAction has to be of the type QAction *[].


Log in to reply
 

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