QAction Group Vs. Vector and Array
-
wrote on 25 Sept 2010, 02:24 last edited by
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
-
wrote on 25 Sept 2010, 07:04 last edited by
[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.
-
wrote on 25 Sept 2010, 07:53 last edited by
You can set a QActionGroup to be exclusive (only one action can be checked at a time). And more probably.
-
wrote on 25 Sept 2010, 16:58 last edited by
[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
-
wrote on 26 Sept 2010, 13:39 last edited by
[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()@
-
wrote on 26 Sept 2010, 14:16 last edited by
Okay, Thanks! I got it now.
-Masoug
-
wrote on 27 Sept 2010, 05:18 last edited by
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
-
wrote on 27 Sept 2010, 08:11 last edited by
masoug, what is myAction in this case and how have it been inititalized?
-
wrote on 28 Sept 2010, 15:04 last edited by
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 *[].
1/9