6

I have created a nice looking toolbar using qt Designer and populated it with some actions.
I tried to connect the actions to slots visually from qt designer by clicking edit> signals and slots. This DID NOT WORK because i could not find any QAction signals.

Question.

Is there a way to connect the QAction SIGNAL(triggered()) to my slots within QT designer? Please help.
PS: I am currently being forced to connect through code:

QObject::connect(myAction, SIGNAL(triggered()),this, SLOT(myActionWasTriggered()))

but ia am lazy and i wish to connect using qt designer.

Dr Deo
  • 4,650
  • 11
  • 43
  • 73

4 Answers4

5

There's "Signal/Slot Editor" docked panel (Toggled with View->Signal/Slot Editor). You can connect your actions there. You may also need to add your custom slots via the "Change signals/slots" form context menu.

To save yourself some work, use the auto-connection feature (see QMetaObject::connectSlotsByName). Basically, all slots named with a specific pattern of on_objectName_signalName will be auto-connected.

enter image description here

Gelldur
  • 11,187
  • 7
  • 57
  • 68
Nikita Nemkin
  • 2,780
  • 22
  • 23
4

Look here in Docs Designer Connection Mode... How to autconnect in the designer

Azd325
  • 5,752
  • 5
  • 34
  • 57
  • then you can use the Autoconnect http://doc.trolltech.com/4.6.2/designer-using-a-ui-file.html#automatic-connections ... with your source files – Azd325 Jan 12 '11 at 16:57
  • 1
    When i try this on the toolbar, i see only the toolbars signals yet I am trying to connect QActions inside the toolbar to some slots. What i want is to see some actions and their signals within qt designer. – Dr Deo Jan 12 '11 at 18:42
3

Use the "Action editor" panel. You can find it near "Signals & Slots editor".

Anteru
  • 19,042
  • 12
  • 77
  • 121
oandrew
  • 31
  • 3
-1

If you have menu, Please name your actions object according to menus , Suppose you have:

File Edit View Tools Help

You have 5 menus bar,

So you'll have a set of action_x , x is a number.Please naming your x according to your menu.

more explaintion:

File = 1
Edit = 2
View = 3
Tools = 4 
Help = 5

And suppose :

File---> Open ..Close
Edit---> find...replace
View---> ZoomIn ... ZoomOut
Tools--->calender... prefrences
help---> help... about

You have 5x2 = 10 , you have 10 action, please manage such as:

action_11 == File>Open
action_12 == File>close
action_21 == Edit>find
and so on..

Above type of managing make easy your coding .....

PersianGulf
  • 2,845
  • 6
  • 47
  • 67