我对QT很新。我一直在为它乱搞一个星期。我碰到一个错误来了,而我是想自定义数据类型添加到的QList像这样(C++ QT)QList只允许附加常量类对象吗?
QObject parent;
QList<MyInt*> myintarray;
myintarray.append(new const MyInt(1,"intvar1",&parent));
myintarray.append(new const MyInt(2,"intvar2",&parent));
myintarray.append(new const MyInt(3,"intvar3",&parent));
和我的敏类是INT一个简单的包装,看起来像这样
#ifndef MYINT_H
#define MYINT_H
#include <QString>
#include <QObject>
class MyInt : public QObject
{
Q_OBJECT
public:
MyInt(const QString name=0, QObject *parent = 0);
MyInt(const int &value,const QString name=0, QObject *parent = 0);
MyInt(const MyInt &value,const QString name=0,QObject *parent = 0);
int getInt() const;
public slots:
void setInt(const int &value);
void setInt(const MyInt &value);
signals:
void valueChanged(const int newValue);
private:
int intStore;
};
#endif
错误我在Qlist追加
error: invalid conversion from 'const MyInt*' to 'MyInt*' error:
initializing argument 1 of 'void QList::append(const T&) [with T = MyInt*]'
如果任何人都可以指出我做错了什么,那就太棒了。
更有意义......谢谢 – colorfulgrayscale 2010-01-07 23:07:49