<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Signals and slots from runtime-loaded UI-files]]></title><description><![CDATA[<p dir="auto">Good Morning!</p>
<p dir="auto">I was just playing with loading UI-files at runtime. I have a menubar with some dropdown menus and some clickable entries. When I click on "Settings", a UI-file will be loaded from the applications resource file and shows up with some buttons and edit fields.</p>
<p dir="auto">My question now is:</p>
<p dir="auto">How can I implement signals and slots for the elements from the UI-files since I have no *.cpp or *.h files for them?</p>
<p dir="auto">Thank you,</p>
<p dir="auto">Ceriana</p>
]]></description><link>https://forum.qt.io/topic/31035/signals-and-slots-from-runtime-loaded-ui-files</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 12:58:37 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/31035.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 22 Aug 2013 13:25:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Signals and slots from runtime-loaded UI-files on Sat, 24 Aug 2013 19:48:09 GMT]]></title><description><![CDATA[<p dir="auto">i done it for you ;)   main.cpp:<br />
@<br />
#include "test.h"<br />
int main(int argc,char* argv[]){<br />
QApplication app(argc, argv);<br />
Ui::Form ui;<br />
ui.setupUi();<br />
return app.exec();<br />
}<br />
@<br />
test.h:<br />
@<br />
#ifndef TEST_H<br />
#define TEST_H</p>
<p dir="auto">#include &lt;QtCore/QVariant&gt;<br />
#include &lt;QtWidgets/QAction&gt;<br />
#include &lt;QtWidgets/QApplication&gt;<br />
#include &lt;QtWidgets/QButtonGroup&gt;<br />
#include &lt;QtWidgets/QHeaderView&gt;<br />
#include &lt;QtWidgets/QPushButton&gt;<br />
#include &lt;QtWidgets/QWidget&gt;<br />
#include &lt;QtCore/QFile&gt;<br />
#include &lt;QtUiTools/QUiLoader&gt;</p>
<p dir="auto">QT_BEGIN_NAMESPACE</p>
<p dir="auto">class Ui_Form:public QWidget<br />
{<br />
Q_OBJECT<br />
private:</p>
<pre><code>QUiLoader loader;
</code></pre>
<p dir="auto">signals:</p>
<pre><code>void call_wid(&amp;#41;;
</code></pre>
<p dir="auto">private slots:</p>
<pre><code>void emitter(&amp;#41;{
    emit call_wid(&amp;#41;;
}

void save(&amp;#41;{
    QFile file&amp;#40;"add.ui"&amp;#41;;  // same directory where program in
    QWidget* my=loader.load(&amp;file,this&amp;#41;;
    my-&gt;setGeometry(QRect(110,100, 125, 33&amp;#41;&amp;#41;;
    my-&gt;show();
}
</code></pre>
<p dir="auto">public:<br />
QPushButton *pushButton;</p>
<pre><code>void setupUi()
{
    this-&gt;setObjectName("Form");
    this-&gt;resize(400, 300);
    pushButton = new QPushButton(this);
    pushButton-&gt;setObjectName("pushButton");
    pushButton-&gt;setGeometry(QRect(110, 20, 125, 33));
    //QWidget *wid = loader.load(&amp;file,Form);
    connect(this, SIGNAL(call_wid()),this,SLOT(save()));
    connect(pushButton, SIGNAL(clicked()),this,SLOT(emitter()));
    this-&gt;setWindowTitle("Form");
    pushButton-&gt;setText("CALL");
    this-&gt;show();
} // setupUi
</code></pre>
<p dir="auto">};<br />
namespace Ui {<br />
class Form: public Ui_Form {};<br />
} // namespace Ui<br />
QT_END_NAMESPACE<br />
#endif // TEST_H<br />
@<br />
and <a href="http://test.pro" target="_blank" rel="noopener noreferrer nofollow ugc">test.pro</a><br />
@<br />
TEMPLATE = app<br />
TARGET = test<br />
INCLUDEPATH += .<br />
QT += widgets uitools<br />
HEADERS += test.h<br />
SOURCES += main.cpp<br />
@<br />
NOTICE: i am on 64bit archlinux desktop with qt 5.1.0<br />
EDIT: Ahh sorry and add.ui:<br />
@<br />
&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;ui version="4.0"&gt;<br />
&lt;widget class="QPushButton" name="pushButton"&gt;<br />
&lt;property name="geometry"&gt;<br />
&lt;rect&gt;<br />
&lt;x&gt;200&lt;/x&gt;<br />
&lt;y&gt;250&lt;/y&gt;<br />
&lt;width&gt;80&lt;/width&gt;<br />
&lt;height&gt;33&lt;/height&gt;<br />
&lt;/rect&gt;<br />
&lt;/property&gt;<br />
&lt;property name="text"&gt;<br />
&lt;string&gt;Save&lt;/string&gt;<br />
&lt;/property&gt;<br />
&lt;/widget&gt;<br />
&lt;/ui&gt;<br />
@</p>
]]></description><link>https://forum.qt.io/post/192414</link><guid isPermaLink="true">https://forum.qt.io/post/192414</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sat, 24 Aug 2013 19:48:09 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and slots from runtime-loaded UI-files on Fri, 23 Aug 2013 15:34:47 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, I have no idead how to use it. I looked up QUiLoader::createWidget() in the Qt Assistant, but when I try to get this list, my program crashes:</p>
<p dir="auto">@<br />
void MainWindow::openSettings()<br />
{<br />
QUiLoader loader;</p>
<pre><code>QFile file&amp;#40;":/test.ui"&amp;#41;;
file.open(QFile::ReadOnly&amp;#41;;

QWidget *wid = loader.load(&amp;file, this);
*this-&gt;widglist = loader.availableWidgets();

wid-&gt;show();
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">Also, I have no idea what this plugin path means, the form is stored inside the resource file.</p>
]]></description><link>https://forum.qt.io/post/192318</link><guid isPermaLink="true">https://forum.qt.io/post/192318</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Fri, 23 Aug 2013 15:34:47 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and slots from runtime-loaded UI-files on Thu, 22 Aug 2013 19:54:57 GMT]]></title><description><![CDATA[<p dir="auto">it seems that QUiLoader::createWidget() is usable for this job.</p>
]]></description><link>https://forum.qt.io/post/192203</link><guid isPermaLink="true">https://forum.qt.io/post/192203</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 22 Aug 2013 19:54:57 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and slots from runtime-loaded UI-files on Thu, 22 Aug 2013 18:18:52 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="SGaist" date="1377182562"]Hi,</p>
<p dir="auto">You would have to create a widget containing the slots needed and call QMetaObject::connectSlotsByName on that widget.</p>
<p dir="auto">Have a look at the Calculator Builder example</p>
<p dir="auto">Hope it helps[/quote]</p>
<p dir="auto">I dont really understand how to do this. I created a QWidget in the mainwindow-class, but I dont understand what you mean by "containing the slots" and which object to pass to connectSlotsByName.</p>
<p dir="auto">The calculator example uses QML, or are there any more calculators I did not see?</p>
<p dir="auto">[quote author="unixmania" date="1377183604"]hi. ui file allow to define connections into itself. e.g  a_ui_file.ui:<br />
@<br />
//<br />
@<br />
[/quote]</p>
<p dir="auto">Yes, but I want to edit the C++ code for those slots, for example if I do changes on a runtime-loaded QDialog, that I can create a save button in whose slot the data from some QLineEdits gets saved into a configurationfile.</p>
]]></description><link>https://forum.qt.io/post/192193</link><guid isPermaLink="true">https://forum.qt.io/post/192193</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 22 Aug 2013 18:18:52 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and slots from runtime-loaded UI-files on Thu, 22 Aug 2013 15:00:04 GMT]]></title><description><![CDATA[<p dir="auto">hi. ui file allow to define connections into itself. e.g  a_ui_file.ui:<br />
@<br />
&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;ui version="4.0"&gt;<br />
&lt;class&gt;Form&lt;/class&gt;<br />
&lt;widget class="QWidget" name="Form"&gt;<br />
&lt;property name="geometry"&gt;<br />
&lt;rect&gt;<br />
&lt;x&gt;0&lt;/x&gt;<br />
&lt;y&gt;0&lt;/y&gt;<br />
&lt;width&gt;400&lt;/width&gt;<br />
&lt;height&gt;300&lt;/height&gt;<br />
&lt;/rect&gt;<br />
&lt;/property&gt;<br />
&lt;property name="windowTitle"&gt;<br />
&lt;string&gt;Form&lt;/string&gt;<br />
&lt;/property&gt;<br />
&lt;widget class="QPushButton" name="pushButton"&gt;<br />
&lt;property name="geometry"&gt;<br />
&lt;rect&gt;<br />
&lt;x&gt;130&lt;/x&gt;<br />
&lt;y&gt;130&lt;/y&gt;<br />
&lt;width&gt;125&lt;/width&gt;<br />
&lt;height&gt;33&lt;/height&gt;<br />
&lt;/rect&gt;<br />
&lt;/property&gt;<br />
&lt;property name="text"&gt;<br />
&lt;string&gt;PushButton&lt;/string&gt;<br />
&lt;/property&gt;<br />
&lt;/widget&gt;<br />
&lt;/widget&gt;<br />
&lt;resources/&gt;<br />
&lt;!-- Begin below --&gt;<br />
&lt;connections&gt;<br />
&lt;connection&gt;<br />
&lt;sender&gt;pushButton&lt;/sender&gt;<br />
&lt;signal&gt;clicked()&lt;/signal&gt;<br />
&lt;receiver&gt;Form&lt;/receiver&gt;<br />
&lt;slot&gt;close()&lt;/slot&gt;<br />
&lt;hints&gt;<br />
&lt;hint type="sourcelabel"&gt;<br />
&lt;x&gt;192&lt;/x&gt;<br />
&lt;y&gt;146&lt;/y&gt;<br />
&lt;/hint&gt;<br />
&lt;hint type="destinationlabel"&gt;<br />
&lt;x&gt;199&lt;/x&gt;<br />
&lt;y&gt;149&lt;/y&gt;<br />
&lt;/hint&gt;<br />
&lt;/hints&gt;<br />
&lt;/connection&gt;<br />
&lt;/connections&gt;<br />
&lt;/ui&gt;<br />
@<br />
Also you can look theese.<br />
<a href="http://qt-project.org/doc/qt-5.1/qtuitools/quiloader.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.1/qtuitools/quiloader.html</a><br />
<a href="http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-loader.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-loader.html</a><br />
<a href="http://qt-project.org/doc/qt-5.1/qtdesigner/qformbuilder.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.1/qtdesigner/qformbuilder.html</a></p>
<p dir="auto">edit: i wonder too.i try it for see whether works or not.</p>
]]></description><link>https://forum.qt.io/post/192181</link><guid isPermaLink="true">https://forum.qt.io/post/192181</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 22 Aug 2013 15:00:04 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and slots from runtime-loaded UI-files on Thu, 22 Aug 2013 14:42:42 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">You would have to create a widget containing the slots needed and call QMetaObject::connectSlotsByName on that widget.</p>
<p dir="auto">Have a look at the Calculator Builder example</p>
<p dir="auto">Hope it helps</p>
]]></description><link>https://forum.qt.io/post/192177</link><guid isPermaLink="true">https://forum.qt.io/post/192177</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 22 Aug 2013 14:42:42 GMT</pubDate></item></channel></rss>