Nio74
15th April 2019, 09:42
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
Backend::Backend(QObject *parent) : QObject(parent)
{
settings = new QSettings("$HOME/.config/MySoft.ini",QSettings::IniFormat);
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(client->tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(gotError(QAbstractSocket::SocketError)));
//connect data to source database
connect(client, &ClientResearch::sendRiparazione, this ,&Backend::recivedRiparazione);
}
QML
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
}
C++ Backend constructor
Backend::Backend(QObject *parent) : QObject(parent)
{
settings = new QSettings("$HOME/.config/MySoft.ini",QSettings::IniFormat);
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(client->tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(gotError(QAbstractSocket::SocketError)));
//connect data to source database
connect(client, &ClientResearch::sendRiparazione, this ,&Backend::recivedRiparazione);
}
QML
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
}