September 25, 2010

masoug masoug
Lab Rat
12 posts

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;

  1. ...
  2. ActionGroup->addAction(myAction);
  3. delete myAction;

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

Thanks!

-Masoug

 Signature 

C++kie Monster

8 replies

September 25, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts
masoug wrote:
Hi, I am just wondering what is so special about QActionGroup. … Does QActionGroup store action objects? -Masoug

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

  1. delete myAction;

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

September 25, 2010

Franzk Franzk
Lab Rat
830 posts

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

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

September 25, 2010

masoug masoug
Lab Rat
12 posts
chetankjain wrote:
If you want to remove myAction from the group, you should just use removeAction(myAction). Calling delete will “delete” myAction.

So if I just call

  1. delete myAction;
will I still be able to find “myAction” in “ActionGroup”? Or does “ActionGroup” have a copy of “myAction”?

Thanks!

-Masoug

 Signature 

C++kie Monster

September 26, 2010

Franzk Franzk
Lab Rat
830 posts
masoug wrote:
So if I just call
  1. delete myAction;
will I still be able to find “myAction” in “ActionGroup”? Or does “ActionGroup” have a copy of “myAction”?

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:

  1. myAction->deleteLater()

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

September 26, 2010

masoug masoug
Lab Rat
12 posts

Okay, Thanks! I got it now.

-Masoug

 Signature 

C++kie Monster

September 27, 2010

masoug masoug
Lab Rat
12 posts

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

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

That was kinda the basis of my question…

Thanks!

-Masoug

 Signature 

C++kie Monster

September 27, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

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

September 28, 2010

Franzk Franzk
Lab Rat
830 posts

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.

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

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

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

 
  ‹‹ Comparing unicode chars      QComboBox always crashes in 64-bit release mode (Qt 4.7) ››

You must log in to post a reply. Not a member yet? Register here!