• 7970阅读
  • 14回复

编译程序时的一个错,不会改…… [复制链接]

上一主题 下一主题
离线kaitokidscs
 
只看楼主 倒序阅读 楼主  发表于: 2010-04-20
我定义了一个类LayerAction,然后在其他.h里定义了private:QList<LayerAction> LayerActionList;
为什么我在它的源文件的一个函数中使用LayerActionList.clear();会报错如下
Unhandled exception at 0x0127741d in ActionLabelingTool.exe: 0xC0000005: Access violation reading location 0x0000001c.

编译倒是通过了。
离线yangfanxing
只看该作者 1楼 发表于: 2010-04-20
编译通过?运行报错误?
PHPWind好恶心。。。不想看这种界面。。。
离线kaitokidscs
只看该作者 2楼 发表于: 2010-04-20
是的,程序编译通过的。运行时跳出这个……
离线wd007

只看该作者 3楼 发表于: 2010-04-20
调试一下看看
欢迎访问我的博客,一起学习提高
http://blog.csdn.net/qter_wd007
离线kaitokidscs
只看该作者 4楼 发表于: 2010-04-20
如果我调试的出来……就不在这问了……主要我不知道这个错是什么原因引起的,我调试就是在LayerActionList.clear();这里弹出这个的……郁闷啊,弄好久了……
离线yangfanxing
只看该作者 5楼 发表于: 2010-04-20
“类”的代码。。。
PHPWind好恶心。。。不想看这种界面。。。
离线kaitokidscs
只看该作者 6楼 发表于: 2010-04-20
#ifndef _LayerAction_h
#define _LayerAction_h

#include <QObject>
#include <QPointF>
#include <QList>
#include <QRectF>
#include "XmlWriter.h"
#include "aContour.h"

//class LayerDepth;
class XmlWriter;
class aContour;

class LayerAction: public QObject
{
    Q_OBJECT


        // the member variables
private:

    QList<bool> a_LabelList; // the flag of whether the point is manually labelled or compute generated
    QList<double> a_DepthList;                                                // the depth, as a variable of frame index
    QString a_LayerName;

    QList<bool> a_IsGlobalLabelList;
    QList<bool> a_IsLocalLabelList;
    QList<bool> a_IsTrackedList;
    QList<bool> a_IsDepthLabeledList;
    int a_NumFrames;   // the total number of frames, accessed by numFrames();
    int a_StartFrame;
    int a_EndFrame; // the start and end frame index, range [0, numFrames()-1]. accessed by startFrame() and endFrame();
    int a_CreatedFrame; // the index of the frame where the object is created;

    QList<aContour> a_contour;

    static int selectedPointIndex;
    static QPointF a_OrgCursorPoint;
public:
    // construction, desctrution, copy, and clear
    LayerAction(void);
    LayerAction(const LayerAction& layerAction);
    ~LayerAction(void);
    LayerAction& operator=(const LayerAction& layerAction);
    void copyData(const LayerAction& layerAction);

    

    inline void a_setLayerName(const QString& name){a_LayerName=name;};
    //void create(int numFrames,int frameIndex,const QPointF& point,int layer_index);
    
    void a_setStartFrame(int startFrame){a_StartFrame=startFrame;};
    void a_create(int numFrames){a_NumFrames=numFrames;};
    //inline void a_setStartFrame(int startFrame){a_StartFrame=startFrame;};
    inline void a_setEndFrame(int endFrame){a_EndFrame=endFrame;};
    inline void a_setCreatedFrame(int createdFrame){a_CreatedFrame=createdFrame;};
    inline void a_setDepth(int frameIndex,double depth){a_DepthList[frameIndex]=depth;};
    inline void a_setGlobalLabel(int frameIndex,bool label){a_IsGlobalLabelList[frameIndex]=label;};
    inline void a_setLocalLabel(int frameIndex,bool label){a_IsLocalLabelList[frameIndex]=label;};
    inline void a_setTracked(int frameIndex,bool label){a_IsTrackedList[frameIndex]=label;};
    inline void a_setDepthLabel(int frameIndex,bool label){a_IsDepthLabeledList[frameIndex]=label;};
    inline void a_setContour(int frameIndex,const aContour& acontour){a_contour[frameIndex]=acontour;};
    
};


#endif
离线kaitokidscs
只看该作者 7楼 发表于: 2010-04-20
#include <QtGui>
#include <iostream>
#include "LayerAction.h"

int LayerAction::selectedPointIndex=0;


LayerAction::LayerAction(void): QObject()
{
    a_NumFrames=0;
    a_StartFrame=0;
    a_EndFrame=0;
    a_CreatedFrame=0;
}

LayerAction::LayerAction(const LayerAction& layerAction):QObject()
{
    copyData(layerAction);
}

LayerAction::~LayerAction(void)
{
}

void LayerAction::copyData(const LayerAction &layerAction)
{
    //a_ContourLabelList=layerAction.a_ContourLabelList;
    a_DepthList=layerAction.a_DepthList;
    a_LayerName=layerAction.a_LayerName;

    a_IsGlobalLabelList=layerAction.a_IsGlobalLabelList;
    a_IsLocalLabelList=layerAction.a_IsLocalLabelList;
    a_IsTrackedList=layerAction.a_IsTrackedList;
    a_IsDepthLabeledList=layerAction.a_IsDepthLabeledList;

    a_NumFrames=layerAction.a_NumFrames;
    a_StartFrame=layerAction.a_StartFrame;
    a_EndFrame=layerAction.a_EndFrame;
    a_CreatedFrame=layerAction.a_CreatedFrame;
}

LayerAction& LayerAction::operator =(const LayerAction &layerAction)
{
    copyData(layerAction);
    return *this;
}
离线kaitokidscs
只看该作者 8楼 发表于: 2010-04-21
...
离线dbzhang800

只看该作者 9楼 发表于: 2010-04-21
引用第8楼kaitokidscs于2010-04-21 10:22发表的  :
...


建议平时看看Qt自带的manual,
Qt manual 或 书籍中都会提到 QObject 不能复制 (复制构造函数和赋值操作符都是private)

from "QObject Class Reference"

No copy constructor or assignment operator

QObject has neither a copy constructor nor an assignment operator. This is by design. Actually, they are declared, but...


from "Qt Object Model"
Qt Objects should be treated as identities, not as values. Identities are cloned, not copied or assigned, and cloning an identity is a more complex operation than copying or assigning a value. Therefore, QObject and all subclasses of QObject (direct or indirect) have their copy constructor and assignment operator disabled.


from "QList Class Reference"
QList's value type must be an assignable data type. This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *.
离线kaitokidscs
只看该作者 10楼 发表于: 2010-04-21
引用第9楼dbzhang800于2010-04-21 11:07发表的  :

我看明白了……那我想要进行这些操作应该怎么办……
离线yangfanxing
只看该作者 11楼 发表于: 2010-04-21
回 10楼(kaitokidscs) 的帖子
引用第9楼dbzhang800于2010-04-21 11:07发表的  :
QList's value type must be an assignable data type. This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *.

这个我不知道自己有没有理解错误。。。
但是QWidget *的话我确实用QList储存过,因为涉及新建多个同类型窗口+关闭某些窗口等。

QObject可能另说,+自定义的继承类。。。

。。。同考证。
PHPWind好恶心。。。不想看这种界面。。。
离线dbzhang800

只看该作者 12楼 发表于: 2010-04-21
Re:回 10楼(kaitokidscs) 的帖子
引用第11楼yangfanxing于2010-04-21 13:45发表的 回 10楼(kaitokidscs) 的帖子 :
这个我不知道自己有没有理解错误。。。
但是QWidget *的话我确实用QList储存过,因为涉及新建多个同类型窗口+关闭某些窗口等。
QObject可能另说,+自定义的继承类。。。
.......

这句话说得就是,你不可以 QList<QWidget>,你应该QList<QWidget*>
离线yangfanxing
只看该作者 13楼 发表于: 2010-04-21
回 12楼(dbzhang800) 的帖子
是呃,英文不过关,看走眼了。
(*^__^*) 。。。
PHPWind好恶心。。。不想看这种界面。。。
离线kaitokidscs
只看该作者 14楼 发表于: 2010-04-21
那么用QLIST存QOBJECT的自定义继承类是可以的咯?QList<XXXX*>?
快速回复
限100 字节
 
上一个 下一个