2

I'm using Qt Creator 3.2.1 based on Qt 5.3.2

When in the designer, you can right click on a pushButton and select "Go to slot ...". A dialogue box opens allowing you to select a slot ... for example Clicked().
Then you will receive autogenerated method

void MyClass::on_Button_clicked()
{}

But I'm using code style in which the method should be named onButtonClicked().
How can I change default code generating template to satisfy me needs?

Temak
  • 2,929
  • 36
  • 49

2 Answers2

3

Qt Designer generated UIs support a feature called Automatic Connections. This will automatically connect signals and slots based on a given naming convention. This is

on_{Sender Object Name}_{Signal}

Every mehtod with this signature and matching Widget/Signal in the UI file will automatically be connected as a slot.

This mechanism is hardcoded in Qt, you cannot change it.

However, you can manually connect signals/slots in the Designer:

  • either go to the signal/slot view (shortcut F4) and drag/drop the objects to select the singals and slots
  • or open the Signal/Slot editor (usually in the lower right area) and add a connection by entering sender, signal, receiver and slot

With these methods, you can choose a slot with any name

Update:
When using a custom widget with your own signals/slots that are not known to QtDesigner, you can add them in Signal/Slot drag and drop method mentioned above. Simply click on the "Change..." button in the popup editor, and add the signature of your signal/slot.

You have to make sure that the concrete Class instantiating the UI actually has these signals/slots.

This is only possible on the root-widget of the UI or placeholder widgets

Community
  • 1
  • 1
king_nak
  • 11,313
  • 33
  • 58
1

I don't think you can change the default name. But what you can do is right click on the generated slot and select 'Refactor->Convert to camel case'

avb
  • 1,701
  • 5
  • 22
  • 37
  • 1
    But then as king_nak pointed it won't be automatically connected and you will need to connect the slot manually. – Temak Apr 27 '15 at 08:52