PDA

View Full Version : why do I need to manualy edit .ui to make Mainwindow slot visible to other senders



polrus
28th April 2017, 22:51
I use Qt Creator for majority of signal-to-slot assignments

In the case of having 2 buttons in MainWindow , with very similar actions I wanted the second of the buttons to trigger the button1-on-click slot of the first one.

Then in the on_click slot I would distinguish by sender()->ObjectName

I used to to this many times - now ( maybe new qt creator version) I cannot see the slot of the first slot in the Mainwidow slots list.
I edited mainwidow.h to move the button1-on-click slot to 'public slots' of MainWindow and rebuilt the project but still this slot did not appear in the list of MainWindows slots .

I found that on the bottom of MainWindow.ui there's a section :
</connections>
<slots>
<slot>something-on-click()</slot>
</slots>
</ui>

By manualy adding <slot>button1-on-click()</slot> to this section I finally got this slot to appear i the list of MainWindow slots i the "signal/slot" editor.

Why do I need to manually add it - I think in the older QT creator I could see all MainWindow slots by default eve without taggint them as public slots in the header file.

Lesiok
29th April 2017, 08:54
1. UI file does not know anything about H file.
2. Rename slot to on_button1_clicked and read about QMetaObject::connectSlotsByName.
3. Don't edit manualy UI files.