Hi. I want to dynamically load a .ui file. I know to use QUILoader.
Supposing the widget the .ui file describes new signals and slots. If this was a compile-time problem, I could generate the ui_foo.h and implement the slot in code.
Since this is all dynamic, when I load the .ui file, the widget will have slots with no definitions. I have constructed a simple example:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="my_widget">
<widget class="QPushButton" name="pushButton">
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>my_slot()</slot>
</connection>
</connections>
<slots>
<slot>my_slot()</slot>
</slots>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="my_widget">
<widget class="QPushButton" name="pushButton">
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>my_slot()</slot>
</connection>
</connections>
<slots>
<slot>my_slot()</slot>
</slots>
</ui>
To copy to clipboard, switch view to plain text mode
Now suppose I do something like this:
QFile file("my_widget.ui");
file.
open(QFile::ReadOnly);
= QWidget * my_widget
= loader.
load(&file,
this);
QUiLoader loader;
QFile file("my_widget.ui");
file.open(QFile::ReadOnly);=
QWidget * my_widget = loader.load(&file, this);
To copy to clipboard, switch view to plain text mode
What happens when I click the button? my_slot() isn't defined.
I want to intercept calls to my_slot but I have no idea how. Something clever with QMetaObject maybe?
Bookmarks