QML check from C ++ signal
I have to check that the user has entered the pc's ip where the socket connects, I have a backend in C ++ where on the constructor I wanted to do this check which then sent a signal to the qml, but I believe that the qml can't do it not being instantiated the Backend class, how could I do?
C++ Backend constructor
Code:
{
settings->setValue("ipcasa","192.168.1.8");
if (settings->contains("ipcasa"))
{
ip = settings->value("ipcasa").toString();
}else {
qDebug() << "insert your Ip";
emit statusChanged(" You must insert to Ip");
client = new ClientResearch(ip,6547);
connect(client, &ClientResearch::hasReadSome, this, &Backend::receivedSomething);
connect(client, &ClientResearch::statusChanged, this, &Backend::setStatus);
// FIXME change this connection to the new syntax
//connect data to source database
connect(client, &ClientResearch::sendRiparazione, this ,&Backend::recivedRiparazione);
}
QML
Code:
ApplicationWindow {
id: window
width: 500
height: 500
visible:true
Backend{
id: backend
onStatusChanged: {
messageDialog.text = newStatus
messageDialog.setVisible(true);
}
}
MessageDialog{
id: messageDialog
title: "Attention"
onAccepted: {
console.log("message for insert ip start.")
// Qt.quit()
}
// Component.onCompleted: visible = true
}
Re: QML check from C ++ signal
A constructor can't really send a signal.
Connections to signals can only be done on fully formed objects, which means the constructor must have completed.
Independent of that: a status is usually something that is always present and only changes from time to time. So the way to expose that to QML is to use a Q_PROPERTY
Cheers,
_