Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Emitting multiple signals from the same onTriggered
Forum Updated to NodeBB v4.3 + New Features

Emitting multiple signals from the same onTriggered

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 3 Posters 529 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rscr
    wrote on last edited by rscr
    #1

    Hi,

    I am having problems to emit 2 signals from the same custom QML Type. I want to run periodically check_conf(), and emit 1, 2 or none signals depending of check_ipConf() and check_gateway().

    The problem is that I am showing the ip and gateway values in two TextFields, and I have always updated the 2nd one (gateway value). The firs one related with the ip value never gets updated.

    I have the next code:

    main.qml

    Timer{
                interval: 1000; running: true; repeat:true
                onTriggered: cp4Conf.check_conf()
            }
    
            QTcp4Conf{
                id: cp4Conf
                onIpChanged: stateGroup.state = 'State1'
                onGatewayChanged : stateGroup.state = 'State2'
             }
    
                    State{
                        name: "State1"
    
                        PropertyChanges {
                            target: page.textIP
                            text: cp4Conf.ip
    
                        }
                    },
    
                    State{
                        name: "State2"
    
                        PropertyChanges {
                            target: page.textGateway
                            text: cp4Conf.gateway
    
                        }
                    }
    

    QTcp4Conf.cpp

    void QTcp4Conf::check_conf(){
    
        QString ipValue, gatewayValue;
    
    
        open_conf(ipValue,gatewayValue);
    
        check_ipConf(ipValue);
        check_gatewayConf(gatewayValue);
    }
    
    
    void QTcp4Conf::open_conf(QString& ipValue, QString& gatewayValue){
    
    
        QSettings fileConf("C:/Data/conf.conf",QSettings::IniFormat);
    
    
        ipValue = fileConf.value("static ip_address").toString();
        gatewayValue = fileConf.value("static routers").toString();
    
    
    }
    
    
    void QTcp4Conf::check_ipConf(QString ipValue){
    
        if(m_ip == ipValue){
            return;
        }
    
        m_ip = ipValue;
    
        emit ipChanged(m_ip);
    }
    
    void QTcp4Conf::check_gatewayConf(QString gatewayValue){
    
        if(m_gateway == gatewayValue){
            return;
        }
    
        m_gateway = gatewayValue;
    
        emit gatewayChanged(m_gateway);
    
    }
    
    QString QTcp4Conf::ip(){
      return m_ip;
    }
    
    QString QTcp4Conf::gateway(){
        return m_gateway;
    }
    
    

    Maybe I can't use this approach?

    Kind regards,

    Rafa

    JKSHJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you show your class definition ?
      Are you sure that signals are emitted ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R rscr

        Hi,

        I am having problems to emit 2 signals from the same custom QML Type. I want to run periodically check_conf(), and emit 1, 2 or none signals depending of check_ipConf() and check_gateway().

        The problem is that I am showing the ip and gateway values in two TextFields, and I have always updated the 2nd one (gateway value). The firs one related with the ip value never gets updated.

        I have the next code:

        main.qml

        Timer{
                    interval: 1000; running: true; repeat:true
                    onTriggered: cp4Conf.check_conf()
                }
        
                QTcp4Conf{
                    id: cp4Conf
                    onIpChanged: stateGroup.state = 'State1'
                    onGatewayChanged : stateGroup.state = 'State2'
                 }
        
                        State{
                            name: "State1"
        
                            PropertyChanges {
                                target: page.textIP
                                text: cp4Conf.ip
        
                            }
                        },
        
                        State{
                            name: "State2"
        
                            PropertyChanges {
                                target: page.textGateway
                                text: cp4Conf.gateway
        
                            }
                        }
        

        QTcp4Conf.cpp

        void QTcp4Conf::check_conf(){
        
            QString ipValue, gatewayValue;
        
        
            open_conf(ipValue,gatewayValue);
        
            check_ipConf(ipValue);
            check_gatewayConf(gatewayValue);
        }
        
        
        void QTcp4Conf::open_conf(QString& ipValue, QString& gatewayValue){
        
        
            QSettings fileConf("C:/Data/conf.conf",QSettings::IniFormat);
        
        
            ipValue = fileConf.value("static ip_address").toString();
            gatewayValue = fileConf.value("static routers").toString();
        
        
        }
        
        
        void QTcp4Conf::check_ipConf(QString ipValue){
        
            if(m_ip == ipValue){
                return;
            }
        
            m_ip = ipValue;
        
            emit ipChanged(m_ip);
        }
        
        void QTcp4Conf::check_gatewayConf(QString gatewayValue){
        
            if(m_gateway == gatewayValue){
                return;
            }
        
            m_gateway = gatewayValue;
        
            emit gatewayChanged(m_gateway);
        
        }
        
        QString QTcp4Conf::ip(){
          return m_ip;
        }
        
        QString QTcp4Conf::gateway(){
            return m_gateway;
        }
        
        

        Maybe I can't use this approach?

        Kind regards,

        Rafa

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        @rscr said in Emitting multiple signals from the same onTriggered:

        The problem is that I am showing the ip and gateway values in two TextFields

        Please post the code that shows how you connect your TextFields.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rscr
          wrote on last edited by
          #4

          Hi,

          QTcp4Conf.h

          #ifndef QTCP4CONF_H
          #define QTCP4CONF_H
          
          
          #include <QObject>
          #include <QDebug>
          
          class QTcp4Conf : public QObject{
          
              Q_OBJECT
          
          
          
              Q_PROPERTY(QString ip
                         READ ip
                         NOTIFY ipChanged)
          
              Q_PROPERTY(QString gateway
                         READ gateway
                         NOTIFY gatewayChanged)
          
          public:
          
              explicit QTcp4Conf(QObject *parent = nullptr);
          
          
               Q_INVOKABLE void check_conf();
          
          
              QString ip();
              QString gateway();
          
              /**
               * @brief open_conf : Abrir archivo de configuracion (.conf)
               * @param ipValue   : Valor IP extraido del .conf
               * @param gatewayValue : Valor gateway extraido del .conf
               */
              void open_conf(QString& ipValue,QString& gatewayValue);
          
              /**
               * @brief check_ipConf : Comprobar si IP ha cambiado, en ese caso, lanzar aviso
               * @param ipValue      : Valor IP extraído del .conf
               */
              void check_ipConf(QString ipValue);
          
              /**
               * @brief check_gatewayConf : Comprobar si gateway ha cambiado, en ese caso, lanzar aviso
               * @param gatewayValue      : Valor gateway extraído del .conf
               */
              void check_gatewayConf(QString gatewayValue);
          
          signals:
          
              void ipChanged(QString ip);
              void gatewayChanged(QString gateway);
          
          private:
              QString m_ip;
              QString m_gateway;
          
          };
          
          
          #endif // QTCP4CONF_H
          

          QTcp4Conf.cpp

          #include "QTcp4Conf.h"
          #include <QSettings>
          
          
          
          QTcp4Conf::QTcp4Conf(QObject *parent):QObject(parent){
              m_ip = "";
              m_gateway = "";
          }
          
          
          void QTcp4Conf::check_conf(){
          
              QString ipValue, gatewayValue;
          
          
              open_conf(ipValue,gatewayValue);
          
              check_ipConf(ipValue);
              check_gatewayConf(gatewayValue);
          }
          
          
          void QTcp4Conf::open_conf(QString& ipValue, QString& gatewayValue){
          
          
              QSettings fileConf("C:/Data/conf.conf",QSettings::IniFormat);
          
          
              ipValue = fileConf.value("static ip_address").toString();
              gatewayValue = fileConf.value("static routers").toString();
          
          
          }
          
          
          void QTcp4Conf::check_ipConf(QString ipValue){
          
              if(m_ip == ipValue){
                  return;
              }
          
              m_ip = ipValue;
          
              emit ipChanged(m_ip);
          }
          
          void QTcp4Conf::check_gatewayConf(QString gatewayValue){
          
              if(m_gateway == gatewayValue){
                  return;
              }
          
              m_gateway = gatewayValue;
          
              emit gatewayChanged(m_gateway);
          
          }
          
          
          QString QTcp4Conf::ip(){
            return m_ip;
          }
          
          QString QTcp4Conf::gateway(){
              return m_gateway;
          }
          

          main.qml

          ApplicationWindow {
              visible: true
              width: 800
              height: 480
              title: qsTr("Tabs")
          
          
              SwipeView {
                  id: swipeView
                  width: 800
                  anchors.fill: parent
          
          
                  Timer{
                      interval: 1000; running: true; repeat:true
                      onTriggered: cp4Conf.check_conf()
                  }
          
          
                  // Configuracion de red de la RPI
                  QTcp4Conf{
                      id: cp4Conf
                      onIpChanged: stateGroup.state = 'State1'
                      onGatewayChanged : stateGroup.state = 'State2'
                   }
          
                  Page1Form {
                      id:page
                  }
          
                  Page2Form {
                      id:page2
                  }
          
          
          
                  StateGroup {
                      id: stateGroup
                      states: [
          
                          State{
                              name: "State1"
          
                              PropertyChanges {
                                  target: page.textIP
                                  text: cp4Conf.ip
          
                              }
                          },
          
                          State{
                              name: "State2"
          
                              PropertyChanges {
                                  target: page.textGateway
                                  text: cp4Conf.gateway
          
                              }
                          }
          
                      ]
          
                  }
          
              }
          
          
              PageIndicator{
                  id: indicator
          
                  count: swipeView.count
                  currentIndex: swipeView.currentIndex
          
                  anchors.bottom: swipeView.bottom
                  anchors.horizontalCenter: parent.horizontalCenter
              }
          }
          

          That's all my code

          Kind Regards

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rscr
            wrote on last edited by
            #5
            Hi,
            
            Can you show your class definition ?
            Are you sure that signals are emitted ?
            

            If I have this in main.qml

            onIpChanged: stateGroup.state = 'State1'
            //onGatewayChanged : stateGroup.state = 'State2'

            The "textIP" TextField shows the desired value, so the ipChanged() is emited.

            If I have:

            onIpChanged: stateGroup.state = 'State1'
            onGatewayChanged : stateGroup.state = 'State2'

            Only the "textGateway" TextField is working

            Any idea?

            JKSHJ 1 Reply Last reply
            0
            • R rscr
              Hi,
              
              Can you show your class definition ?
              Are you sure that signals are emitted ?
              

              If I have this in main.qml

              onIpChanged: stateGroup.state = 'State1'
              //onGatewayChanged : stateGroup.state = 'State2'

              The "textIP" TextField shows the desired value, so the ipChanged() is emited.

              If I have:

              onIpChanged: stateGroup.state = 'State1'
              onGatewayChanged : stateGroup.state = 'State2'

              Only the "textGateway" TextField is working

              Any idea?

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by JKSH
              #6

              @rscr said in Emitting multiple signals from the same onTriggered:

              If I have this in main.qml

              onIpChanged: stateGroup.state = 'State1'
              //onGatewayChanged : stateGroup.state = 'State2'

              The "textIP" TextField shows the desired value, so the ipChanged() is emited.

              If I have:

              onIpChanged: stateGroup.state = 'State1'
              onGatewayChanged : stateGroup.state = 'State2'

              Only the "textGateway" TextField is working

              Both of your signals are emitted.

              However, you cannot use a StateGroup to change your text like that. When it enters State1, then textGateway changes back to the default value. When it enters State2, then textIP changes back to the default value.

              Just update the text directly in the onIpChanged and onGatewayChanged signal handlers:

              QTcp4Conf {
                  id: cp4Conf
                  onIpChanged: page.textIP.text = cp4Conf.ip
                  onGatewayChanged : page.textGateway.text = cp4Conf.gateway
              }
              

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              3
              • R Offline
                R Offline
                rscr
                wrote on last edited by
                #7

                Thanks, that is working

                Kind Regards

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved