Temak
Temak

Reputation: 3009

Qt Creator. Change code generating template for slots

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?

Upvotes: 3

Views: 2165

Answers (2)

king_nak
king_nak

Reputation: 11513

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

Upvotes: 3

avb
avb

Reputation: 1751

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'

Upvotes: 1

Related Questions