Qt-interest Archive, January 2007
Designer, slots and code
Message 1 in thread
With QT3, it was posssible in designer to identify 'external' receivers and
slots (by external, I mean slots not in the ui).
I understand it's not possible now with QT4 (Or I did not find how to).
However, I have make a quick hack, just to make sure it could work :
I have this .ui file that defines a QMainWindow (say the widget name is
MainWindow)
I have a 'MainWindow.cpp' code saying
MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
{
ui.setupUi(this);
connect(ui.buttonFileOpen,SIGNAL(clicked()),SLOT(slot_fileOpen()));
}
void MainWindow::slot_fileOpen()
{
Do_Whaterver();
}
which makes pressing the button 'do_whaterver' work
I have to use the 'connect' in the code because I did not find anything in
Designer to insert it in the .ui file.
However, when I manually add the .ui syntax in the ui file :
<connections>
<connection>
<sender>buttonFileOpen</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>slot_fileNewBoard()</slot>
...
</connection>
</connections>
and I suppress the code line (connect(ui. ... )
it works all the same !
Am i missing something in Designer, or is there a sadly missing feature that
would spare much time and codeness ?
--
[ signature omitted ]
Message 2 in thread
On 23.01.07 22:14:22, eb wrote:
> With QT3, it was posssible in designer to identify 'external' receivers and
> slots (by external, I mean slots not in the ui).
>
> I understand it's not possible now with QT4 (Or I did not find how to).
Right.
> I have to use the 'connect' in the code because I did not find anything in
> Designer to insert it in the .ui file.
>
> However, when I manually add the .ui syntax in the ui file :
>
> <connections>
> <connection>
> <sender>buttonFileOpen</sender>
> <signal>clicked()</signal>
> <receiver>MainWindow</receiver>
> <slot>slot_fileNewBoard()</slot>
> ...
> </connection>
> </connections>
>
> and I suppress the code line (connect(ui. ... )
>
> Am i missing something in Designer, or is there a sadly missing feature that
> would spare much time and codeness ?
No, you don't miss anything. Designer doesn't support to create such .ui
contents via the UI. However the uic which is used to generate code from
the XML doesn't know that the slot "slot_fileNewBoard()" exists, it just
generates code from the XML. Only designer knows about the slots of the
widgets in the form.
Andreas
--
[ signature omitted ]
Message 3 in thread
Hello,
there is another way to connect slots to ui-signals without doing a
manual connect and without editing the ui-file: name you slot
on_<nameOfWidget>_<signalName>, and it will be connected automatically
when setupUi() is called. E.g. on_pushButton_clicked will be connected
to the signal "clicked" of the push button named "pushButton". That
saves some work and some lines of code ;-)
Ralf
Andreas Pakulat schrieb:
> On 23.01.07 22:14:22, eb wrote:
>> With QT3, it was posssible in designer to identify 'external' receivers and
>> slots (by external, I mean slots not in the ui).
>>
>> I understand it's not possible now with QT4 (Or I did not find how to).
>
> Right.
>
>> I have to use the 'connect' in the code because I did not find anything in
>> Designer to insert it in the .ui file.
>>
>> However, when I manually add the .ui syntax in the ui file :
>>
>> <connections>
>> <connection>
>> <sender>buttonFileOpen</sender>
>> <signal>clicked()</signal>
>> <receiver>MainWindow</receiver>
>> <slot>slot_fileNewBoard()</slot>
>> ...
>> </connection>
>> </connections>
>>
>> and I suppress the code line (connect(ui. ... )
>>
>> Am i missing something in Designer, or is there a sadly missing feature that
>> would spare much time and codeness ?
>
> No, you don't miss anything. Designer doesn't support to create such .ui
> contents via the UI. However the uic which is used to generate code from
> the XML doesn't know that the slot "slot_fileNewBoard()" exists, it just
> generates code from the XML. Only designer knows about the slots of the
> widgets in the form.
>
> Andreas
>
--
[ signature omitted ]