【发布时间】:2010-01-07 22:32:51
【问题描述】:
我对 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));
我的 MyInt 类是一个简单的 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 附加期间遇到的错误
错误:从 'const 进行的无效转换 MyInt*' 到 'MyInt*' 错误:
初始化 'void 的参数 1 QList::append(const T&) [with T = MyInt*]'
如果有人能指出我做错了什么,那就太棒了。
【问题讨论】: