[solved] Where is the glue code?
-
If I create a simple widget based application, that has one push button on its form. In die QtDesigner I connect the release() signal with a slot function (context menu, "go to slot").
And the slot function simply quits:
@void MainWindow::on_pushButton_released()
{
this->close();
}@So far, so good, it works.
But where do I find the glue code that connects the signal with the slot? In the .ui file there is nothing, all .h and .cpp files give no clue. There is only the function for itself and somehow it is connected (by magicg). Is there somewhere a file with the actual code or is there a hidden .xml (or whatever) file that is interpreted during runtime?
-
Nope, there is no such file. The glue you are looking for is in the _ui.h file that is generated at compile time from the .ui file.
Note that you are probably better of making the connections between signals and slots explicitly, rather than relying on the auto-connect feature. So, in your constructor, after the setupUi() call, you expliclity put
@
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(close()));
@No need for a slot like you wrote, as close() already is a slot that you can connect to directly.
-
Isn't the information in the .ui file, under a property called "connections"?
The XML code contains both information for the widget layout, and the signal/slot connections; it's converted to C++ code first, then into binary, during compilation.
-
@Andre: thank you! There must be still one place where the information is stored - even during compile time the compiler must know what to connect.
But you gave me the important info: do it yourself in code ;-)@JKSH: that's true for connections that were made in the Slot/Connections view (F4) but not for those in the context menu, that made me so curious ;-)
BTW: how can I mark this thread as solved?
-
-
If you really want to see the 'magic behind' feel free to take a look at "QMetaObject::connectSlotsByName":http://qt.gitorious.org/qt/qt/blobs/4.8/src/corelib/kernel/qobject.cpp#line3349, which is called from <code>setupUi</code> and automatically connects any slots following a "specific naming convention":http://qt-project.org/doc/qt-4.8/qmetaobject.html#connectSlotsByName.
-
That's too deep into c++ for me right now, but I may take a look in future. Thanks for the link!