Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

strange bug QML / C++



  • Hello, i have problem in my application, i use signal C++ and slot QML.

    application is a protocol analyser, in C++ manage protocol, display in QML.

    i have object qml that have multiple connection in object C++.
    Link for display value, link to timeOut value...

    I use like this:

    var objChamps = appli.lstProt[l_champs[0]].lstTrame[l_champs[1]].lstChamps[l_champs[2]]
    //ObjChamps is an object C++, use Q_Property
    objChamps.dataChange.disconnect(sigReceivedValue)
    objChamps.timeOutChamps.disconnect(sigTimeOutChamp)
    

    It seem to work but i have add other signal timeOut signal
    if query in protocol trig a timeOut, all this object qml connected must be trigged timeOut.

    i have a slot sigTimeOutChamp in qml , i search what object trigged (tab of object connected)
    and trig signal timeout of item qml witch the i of tab

     signal  timeOut(var iObject)
    

    when i call in QML itemdash.timeOut(iTab) //this line emit C++ property getdataRate()
    a CPP property was call in debug and no have reason to have this call.

      function sigTimeOutChamp(sender)
    {
        console.log("sigTimeOutChamp",target.objectName,sender,sender.name,sender.str)
    
        var iTab = searchSender(sender.str)
    
        if (iTab >= 0)
        {
            console.log("emit timeOut:",target.objectName,sender.name,sender.str,iTab,itemdash,itemdash.timeOut)
            itemdash.timeOut(iTab) //this line emit C++ property getdataRate()
            console.log("fin timeOut()")
        }
        else
            console.log("sig timeout not emit:",target.objectName,sender.name,sender.str)
    }
    

    trace:

    timeOut
    cpp: emit timeOut: Champs(0x32ef7f58) "poids brut"
    qml: sigTimeOutChamp BrutValue Champs(0x32ef7f58) poids brut champs-0-1-0
    qml: lg: 2 champs-0-1-0
    qml: emit timeOut: BrutValue poids brut champs-0-1-0 0 ItemDash_QMLTYPE_87(0x55988918) function() { [code] }
    getDataRate null ADS1115::enum_data_rate Champs::getDataRate() Champs(0x32ef7f58)
    
    #ifndef CHAMPS_H
    #define CHAMPS_H
    
    #include <QObject>
    #include "courbe.h"
    #include <QVariant>
    #include <QTime>
    #include "adc.h"
    #include "canbus/CANopen/CanOpenDefs.h"
    #include <QScriptEngine>
    
    class Protocole;
    class Trame;
    
    union{
       struct {
           quint32 countMicroSec;
           quint8  JantePouce;
       }ConfigSpeed;
    
       struct {
           double nbPeriodeParRev;
           quint32 countMicroSec;
    
       }ConfigRpm;
    
       struct {
           quint8 resAdc;
           quint8 multiplicator;
           double VoltMax;
       }ConfigAdc;
    
    }ConfigChamps;
    
    
    
    //    struct t_tx_can{
    //        quint16   m_modeTx;
    //        CanOpenIndex    m_index;
    //        CanOpenSubIndex m_subIndex;
    //        QString         m_tx_data;
    //        CanOpenCobId    m_cobId_tx; //Node si SDO
    //        QTimer          m_timer_tx;
    
    //        quint32     m_tx;
    //        quint32     m_tx_ok;
    //        quint32     m_tx_ko;
    //      };
    
    
    
    
    
    
    
    
    
    class Champs: public QObject
    {
       Q_OBJECT
       Q_PROPERTY(Champs*   champsConnected READ getChampsConnected WRITE setChampsConnected)
       Q_PROPERTY(Trame*    myTrame            READ getTrame )
       Q_PROPERTY(QString   name               READ getName WRITE setName NOTIFY nameChanged)
       Q_PROPERTY(bool      logged             READ isLogged WRITE setLogged)
       Q_PROPERTY(quint32   nbPtsFctTransfert  READ getNbPtsFctTransfert  )
       Q_PROPERTY(quint32   iChamps            READ getIndice )
       Q_PROPERTY(QString   str                READ toString()  )
    
       //ADC
       Q_PROPERTY(ADS1115::enum_status_mux input     READ getInputMux  WRITE setInputMux  NOTIFY AdcInputMutexChange)
       Q_PROPERTY(ADS1115::enum_data_rate  dataRate  READ getDataRate  WRITE setDataRate  NOTIFY AdcDataRateChange)
       Q_PROPERTY(ADS1115::enum_status_fs  fullScale READ getFullScale WRITE setFullScale NOTIFY AdcFullScaleChange)
    
       //LIAISON_RS
       Q_PROPERTY(quint32 offset READ getOffset WRITE setOffset)
       Q_PROPERTY(EnumTypeData typeData READ getDataType WRITE setDataType )
       Q_PROPERTY(EnumEndian endian READ getEndian WRITE setEndian)
       Q_PROPERTY(QVariant valueLin READ getDataLin WRITE setDataLin)
       Q_PROPERTY(QVariant valueOr READ  getDataOr WRITE  setDataOr)
       Q_PROPERTY(QString strChecksum READ getCheckSum WRITE setChecksum)
       Q_PROPERTY(bool    isChecksumOK READ getCheckSumOK NOTIFY fctChecksumValid)
    
    public:
       enum EnumTypeData   {U8=0,S8,U16,S16,U24,S24,U32,S32,FLOAT,DOUBLE,ASCII,ASCII_DOUBLE,CRC};
       Q_ENUM(EnumTypeData)
       enum EnumTypeChamps {NORMAL,ENTREE_ANA,SPEED,RPM};
       enum EnumEndian     {LSB_FIRST,MSB_FIRST,LSB_FIRST_16B};
       Q_ENUM(EnumEndian)
    
    
    
       //enum EnumTypeTrame {TRAME_TX=0,TRAME_RX};
       QString getCheckSum();
       void setChecksum(QString pStr);
       bool getCheckSumOK();
    
    
    
       Champs(Trame  *Parent);
       Champs(Trame  *Parent,QString Name);
       Champs(Trame  *Parent,QString Name,EnumTypeData Type);
       Champs(Trame  *Parent,QString Name,EnumTypeData Type,EnumEndian Endian);
       Champs(Trame  *Parent,QString Name,EnumTypeData Type,EnumEndian Endian,quint32 offset);
       Champs(Trame  *Parent,Champs* pChamps);
    
    
       ~Champs();
    
       Q_INVOKABLE QString getName();
       void    setName(QString name);
    
       //Q_INVOKABLE void setAdjust(bool pAdjust);
    
       QByteArray getByteArray();
    
       //Pour protocol
       quint32 getOffset();
       void    setOffset(quint32 p_offset);
    
       Q_INVOKABLE quint32    getNbOctet();
         quint32 setNbOctet(quint32 pOctet);
    
       EnumTypeData getDataType();
       void setDataType(EnumTypeData p_DataType);
    
       EnumEndian getEndian();
       void       setEndian(EnumEndian firstByte);
    
       bool offsetIsInChamps(int pOffset);
    
     // CanOpenCobId getCobIdRx();
      void StartTimerRx();
    
    
      ADS1115::enum_data_rate getDataRate();
      void setDataRate(ADS1115::enum_data_rate p_dataRate);
    
       ADS1115::enum_status_mux getInputMux();
       void setInputMux(ADS1115::enum_status_mux p_input);
    
       ADS1115::enum_status_fs getFullScale();
       void setFullScale(ADS1115::enum_status_fs p_fullScale);
    
       Q_INVOKABLE void addPointFctTransfert();
       void AddPointFctTransfert(double p_x,double p_y);
       Q_INVOKABLE void suppPointFctTransfert(int t);
    
       quint32 getNbPtsFctTransfert();
      Q_INVOKABLE double  getxFctTransfert(int i);
       Q_INVOKABLE double  getyFctTransfert(int i);
      Q_INVOKABLE void    setxFctTransfert(int i,double value);
      Q_INVOKABLE void    setyFctTransfert(int i,double value);
       Q_INVOKABLE void    triFctTransfert();
    
       QVariant getDataOr(void);
       Q_INVOKABLE QVariant getDataLin(void);
       void setDataLin(QVariant pVar);
    
    
       QByteArray getData();
    
       Q_INVOKABLE void setData(double valueOr,double linea); //pour set du javascript pour test sans passer par le wrapper
       Q_INVOKABLE void setDataOr(QVariant valueOr);
       Q_INVOKABLE void setDataMasque(QVariant pVar, int masque);
    
       void    setDataOffset(int offset, quint16 pdata);
       quint16 getDataOffset(int offset);
    
       bool isLogged();
       void setLogged(bool pBool);
    
    
    
       bool isLastLogged();
    
       Q_INVOKABLE quint32 getIndice();
    
    
    
       Trame * getTrame();
    
    
       QVariant CallCrc(QByteArray *pTrame);
    
     Champs* getChampsConnected();
     void    setChampsConnected(Champs* pChamps);
    
       QString toString();
    
      void emitDataChange(const QVariant dataOr,const QVariant dataLin,const QDateTime timeProt);
    
    signals:
       void dataChange(QObject *sender,const QVariant dataOr,const QVariant dataLin,const QDateTime timeProt); //,const QTime timeNewTrame
       void nameChanged();
    
       void AdcInputMutexChange();
       void AdcDataRateChange();
       void AdcFullScaleChange();
       void timeOutChamps(QObject *sender);
       void fctChecksumValid();
    
    public slots:
       void dataReceived(QObject *sender,const QVariant dataOr,const QVariant dataLin,const QDateTime timeProt);
    
    private:
       //Protocole *MonProt;
       Trame     *MaTrame;
       quint32    MoniChamps;
    
       Champs*    m_ChampsConnected;
       void AffecteNbOctet();
    
    
       QString          Name;
       quint32          m_offset;
       quint32          nbOctets;
       EnumEndian       endian;
       EnumTypeData     DataType;
       EnumTypeChamps   TypeChamps;
    
       Courbe       FctTransfert;
       QVariant     dataProt;
       QVariant     dataLinea;
       bool         Logged;
      // bool         Adjust;
    
       QScriptEngine m_engine;
       QScriptValue  m_fct_checksum;
       QString m_fct_checksum_str;
       bool m_fct_checksum_ok;
    
       void setDataByteArray(QByteArray data);
       QVariant arrondi(double pDouble);
       void setDataReal(QVariant pDouble);
       void setDataString(QVariant pStr);
       void swapByteArray(QByteArray *pByteArray);
    
    
    
    };
    
    Q_DECLARE_METATYPE(Champs*)
    
    #endif // CHAMPS_H
    

    sometimes have a slot qml work... memory problem?


Log in to reply