Results 1 to 2 of 2

Thread: QML check from C ++ signal

  1. #1
    Join Date
    Feb 2018
    Posts
    24
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default 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

    Qt Code:
    1. Backend::Backend(QObject *parent) : QObject(parent)
    2.  
    3.  
    4. {
    5. settings = new QSettings("$HOME/.config/MySoft.ini",QSettings::IniFormat);
    6.  
    7. settings->setValue("ipcasa","192.168.1.8");
    8. if (settings->contains("ipcasa"))
    9. {
    10. ip = settings->value("ipcasa").toString();
    11.  
    12. }else {
    13.  
    14. qDebug() << "insert your Ip";
    15. emit statusChanged(" You must insert to Ip");
    16.  
    17.  
    18. client = new ClientResearch(ip,6547);
    19.  
    20. connect(client, &ClientResearch::hasReadSome, this, &Backend::receivedSomething);
    21. connect(client, &ClientResearch::statusChanged, this, &Backend::setStatus);
    22. // FIXME change this connection to the new syntax
    23. connect(client->tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
    24. this, SLOT(gotError(QAbstractSocket::SocketError)));
    25.  
    26. //connect data to source database
    27. connect(client, &ClientResearch::sendRiparazione, this ,&Backend::recivedRiparazione);
    28.  
    29.  
    30.  
    31.  
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 

    QML

    Qt Code:
    1. ApplicationWindow {
    2. id: window
    3. width: 500
    4. height: 500
    5.  
    6. visible:true
    7.  
    8.  
    9.  
    10. Backend{
    11. id: backend
    12.  
    13. onStatusChanged: {
    14.  
    15.  
    16. messageDialog.text = newStatus
    17. messageDialog.setVisible(true);
    18. }
    19.  
    20.  
    21. }
    22.  
    23. MessageDialog{
    24.  
    25. id: messageDialog
    26. title: "Attention"
    27. onAccepted: {
    28. console.log("message for insert ip start.")
    29. // Qt.quit()
    30.  
    31. }
    32. // Component.onCompleted: visible = true
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Nio74; 15th April 2019 at 10:48.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

Similar Threads

  1. Replies: 1
    Last Post: 26th October 2015, 09:20
  2. QTestLib: check if the signal has a std::string type
    By tarod in forum Qt Programming
    Replies: 4
    Last Post: 14th December 2012, 11:20
  3. Help! How to implement CHECK & RETURN in signal/slots
    By apollocheun in forum Qt Programming
    Replies: 4
    Last Post: 23rd July 2010, 10:51
  4. how to check if a signal in emited or not??
    By sudhansu in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2009, 09:51
  5. check box and signal
    By mickey in forum Newbie
    Replies: 7
    Last Post: 10th November 2007, 15:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.