QList strange issue:Qt4.8.4 opensource with VS express 2010



  • I happened a strange QList issue, QList can't get list memebers

    in my application I wrote three class YDBCManager,YDBCMsg,YDBCSig(Ref code following:)

    and use QList to save the class pointer , like QList <YDBCSig *> m_listSigs; QList <YDBCMsg *> m_listMsgs;

    YDBCManager manange the QList <YDBCMsg *> m_listMsgs,
    YDBCMsg manange QList <YDBCSig *> m_listSigs;

    YDBCManager--->QList<*YDBCMsg>--->QList<*YDBCSig>

    when I want use code like following ,

    YDBCManager * m_dbcmanager // this declare in the QMainwinows:

    @
    QMainwinows::slotReadSig()
    {
    YDBCMsg * tmpmsg=NULL;
    YDBCSig * tmpsig=NULL;--

    for(int i=0;i<m_dbcmanager ->m_listMsgs.size();i++){
    tmpmsg=m_dbcmanager->m_listMsgs.at(i);
    out<<"\nMSG:"<<tmpmsg->getMsgName()<<" ID:"<<m_listMsgs.at(i)->getMsgID()<<"\n";
    out<<"\t cyclic time:"<<tmpmsg->getMsgcycleTime()<<"\n";

    @
    @
    ===> error can't get the size()
    for(int j=0;j<m_dbcmanager ->m_listMsgs.at(i)->m_listSigs->size();j++){
    tmpsig=m_dbcmanager->m_listMsgs.at(i)->m_listSigs->at(j);
    out<<"\t sig["<<j+1<<"]:"<<tmpsig->getSigName()<<"\n";

    }
    //yDebug(m_dbcmanager->m_listMsgs.at(i)->getMsgName());
    }

    @
    }
    I can't get tmpsig, and get the list size,
    happend error "Access violation reading location "

    is My class definition some problem ,or QList can't put sub class of QLIST?

    Any comment welcome!

    //////////////////////////////////////////////////////////
    //// class definition
    ///////////////////////////////////////////////////////////
    @#ifndef YDBCMSG_H

    #define YDBCMSG_H

    #include <QList>

    #include <QString>

    typedef struct _stuTIME_CYCLE{

    int id;
    
    int time;
    

    }stuTIME_CYCLE;

    //////////////////////////////

    //class YDBCSig

    //
    //////////////////////////////

    class YDBCSig

    {

    public:

    YDBCSig(const QString & name, int pos,int len);
    
    virtual ~YDBCSig();
    
    
    
    void setSigName(const QString&str);
    
    QString getSigName();
    
    
    
    void setBitPos(int pos);
    
    int getBitPos();
    
    
    
    void setBitLength(int len);
    
    int getBitLength();
    
    
    
    void setSigValue(int v);
    
    int getSigValue();
    
    
    
    void setSigID(int id);
    
    int getSigID();
    

    private:

    QString m_sigName;
    
    int m_bitPos;
    
    int m_bitLength;
    
    int m_sigValue;
    
    int m_sigID;
    

    };

    //////////////////////////////

    //class YDBCMsg

    //

    //////////////////////////////

    class YDBCMsg

    {

    public:

    YDBCMsg(const QString &name,int id,int len);
    
    virtual ~YDBCMsg();
    
    
    
    unsigned char *getMsgFrame();
    
    
    
    void add2list(YDBCSig * sig);
    
    
    
    void setNodeName(const QString&str);
    
    QString getNodeName();
    
    
    
    void setMsgName(const QString&str);
    
    QString getMsgName();
    
    
    
    void setMsgID(int id);
    
    int getMsgID();
    
    
    
    void setMsgLen(int len);
    
    int getMsgLen();
    
    
    
    void setMsgCycleTime(int t);
    
    int getMsgcycleTime();
    
    
    
    
    
    void setSigValue(int pos,int len,int val);
    

    private:

        QString m_msgNode;
    
        QString m_msgName;
    
        int m_msgID;
    
        int m_msgLength;
    
        int m_msgCycleTime;
    
        unsigned char m_msgData[8];
    

    public:

        QList <YDBCSig *> m_listSigs;
    
    
    
        stuTIME_CYCLE m_timecycle[28];
    

    };

    //////////////////////////////

    //class YDBCManager

    //

    //////////////////////////////

    class YDBCManager

    {

    public:

    YDBCManager(const QString &fn);
    
    ~YDBCManager();
    
    
    
    bool file2msgs();
    
    
    
    void setMsgLen(int len);
    
    int getMsgLen();
    
    
    
    void add2list(YDBCMsg* msg);
    
    
    
    QList <YDBCMsg *> m_listMsgs;
    

    protected:

    bool trainLineStr(const QString &str);// how much signal
    
    bool isMsgLine(const QString &line);
    
    bool isSigLine(const QString&line);
    
    bool readSigLine(const QString &line,QString &sig,int &pos,int &size);
    
    bool readMsgLine(const QString &line,QString &msg,int &is, int len);
    

    private:

    int m_msgLen;
    
    QString m_fileName;
    

    };

    #endif // YDBCMSG_H@



  • Please use code tags, your code is unreadable. Just put a @ at the start and the end of every code...


  • Moderators

    Hi,

    first of all, please use code tags!

    Second i can't even guess what you are trying to say:
    [quote author="htyoung" date="1369192816"]
    but application is crash cause can't access QList <YDBCSig *> m_listSigs's member ,
    after analysis I found the m_listSigs's memeber which can't access ,and I always can't get correct QList <YDBCSig *> m_listSigs memeber,
    and m_listMsgs's member is OK .

    ...

    Is QList can't put two stage( QList<*YDBCMsg>--->QList<*YDBCSig>), means no two stage for QList in function[/quote]

    Third: post a call stack of the crash.

    Fourth: Show the code where the crash happens.


  • Lifetime Qt Champion

    Hi,

    To add up to raven-worx: You don't check that any of your pointer is valid


  • Moderators

    where do you fill up your list?

    what is the output of the following code?
    @
    QMainwinows::slotReadSig()
    {
    foreach( YDBCMsg * tmpmsg, m_dbcmanager->m_listMsgs )
    {
    qDebug() << "YDBCMsg*" << ((void*)tmpmsg);

        foreach(YDBCSig * tmpsig, tmpmsg->m_listSigs)
        {
            qDebug() << "YDBCSig*" << ((void*)tmpsig);
        }
    }
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.