QUiLoader with signals and slots
-
My project is all based on QUiLoader, ie, all interfaces are generated dynamically.
I created a form with Qt Creator for the user to enter the parameters for the database connection. When clicked [OK] data from QLineEdit should be passed to the QSettings object. How to using signals and slots with QUiLoader?Below, my methods of reading and writing settings. writeSettings calls the settings form.
@QHash DataAccess::readSettings()
{
QSettings connecsettings( QSettings::IniFormat, QSettings::SystemScope, "Freedom", "TecTracker");QHash<QString, QVariant> *parameter = new QHash<QString, QVariant>();
connecsettings.beginGroup("Connection");
if(!connecsettings.contains("host"))
writeSettings(&connecsettings);parameter->insert("host", connecsettings.value("host", "127.0.0.1"));
parameter->insert("port", connecsettings.value("port", 5432);
parameter->insert("database", connecsettings.value("database"));
parameter->insert("user", connecsettings.value("user", "postgres"));
parameter->insert("passw", connecsettings.value("passw", "postgres"));connecsettings->endGroup();
return parameter;
}void DataAccess::writeSettings(QSettings* settings)
{
DynamicQtWidgets* guigenerator = new DynamicQtWidgets("configconnec.ui", this);
QDialog *confconnec = guigenerator->createWidget();
confconnec->show();
}@Searching the forum I found a similar "topic":http://qt-project.org/forums/viewthread/31605. but the answers did not help me. There is an answer stating that signals and slots can be implemented in the ui file. How to do this with Qt Creator? Would be in the "Signals & Slots Editor" tab of the designer mode?
!http://i58.tinypic.com/2mgw3l0.png(Signals & Slots Editor)!
? -
- Get the reference of lineEdit and Button(which you click ok)
- Write your own slot in your own class file
- Connect the either lineEdit or Button signal with your slot defined in Step#2,
- Inside your slot, do whatever the custom logic required
-
It is not possible to do this in the ui file? Ie I create the slot in my class, but the connection to the signal leaving in the ui file?
Something like
@ <sender>qdbb_okcancel</sender>
<signal>accept()</signal>
<receiver>MyClass</receiver>
<slot>setSettings()</slot>@I wanted to avoid manipulation of the GUI in code
-
@Exotic_Devel
I have the same demand as your (save signal and slot into ui file) but sadly,
I tried to make a connection of "button clicked" dignal to a slot but there are no change in *.ui file.
The change affect to the source code, not on *.ui file. -
@VoLinhTruc
I do not use "auto connection from Designer", but so far as I am aware that works by naming the slots correspondingly to the signals, and then having a single call in the source code to void QMetaObject::connectSlotsByName(QObject *object). See https://doc.qt.io/qt-5/qobject.html#auto-connection and https://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections. This means there will nothing in the.ui
file for the connection, it will be done by name during initialisation of the designed widget.