QList添加自定义数据结构出错

xuwq2015 2015-06-10 04:49:36
这是我自定义的一个类:

class ConcentratorInfo : public QObject
{
Q_OBJECT

public:
explicit ConcentratorInfo(QObject *parent = 0);

public:
//集中器id
QString id;

//集中器地址
int addr;

//套接字
QTcpSocket *socket;

QString initTime;

//集中器在线状态
int status;

QString quiryTime;

//线程地址
DownService *downService;

/*终端数传机延时时间*/
int rts;

/*终端作为启动站允许发送传输延时时间*/
int sendPropagationDelay;

/*终端等待从动站响应的超时时间和重发次数*/
int responseTimeoutSecond;
int responseTimeoutFrequency;

/*需要主站确认的通信服务(CON=1)的标志*/
int needVerifyService;

/*心跳周期*/
int heartbeatPeriod;

/*主站地址*/
int masterIP1;
int masterIP2;
int masterIP3;
int masterIP4;
/*主站端口号*/
int masterPort;
/*备用ip*/
int alternateIP1;
int alternateIP2;
int alternateIP3;
int alternateIP4;
/*备用端口号*/
int alternatePort;
/*APN*/
QString apn;

public:
Q_INVOKABLE QString idRead();
Q_INVOKABLE void idWrite(QString);

Q_INVOKABLE QString addrRead();
Q_INVOKABLE void addrWrite(QString);

Q_INVOKABLE int statusRead();
Q_INVOKABLE void statusWrite(int);

Q_INVOKABLE int rtsRead();
Q_INVOKABLE void rtsWrite(int);

Q_INVOKABLE int sendPropagationDelayRead();
Q_INVOKABLE void sendPropagationDelayWrite(int);

Q_INVOKABLE int responseTimeoutSecondRead();
Q_INVOKABLE void responseTimeoutSecondWrite(int);

Q_INVOKABLE int responseTimeoutFrequencyRead();
Q_INVOKABLE void responseTimeoutFrequencyWrite(int);

Q_INVOKABLE int needVerifyServiceRead();
Q_INVOKABLE void needVerifyServiceWrite(int);

Q_INVOKABLE int heartbeatPeriodRead();
Q_INVOKABLE void heartbeatPeriodWrite(int);

Q_INVOKABLE int masterIP1Read();
Q_INVOKABLE void masterIP1Write(int);

Q_INVOKABLE int masterIP2Read();
Q_INVOKABLE void masterIP2Write(int);

Q_INVOKABLE int masterIP3Read();
Q_INVOKABLE void masterIP3Write(int);

Q_INVOKABLE int masterIP4Read();
Q_INVOKABLE void masterIP4Write(int);

Q_INVOKABLE int masterPortRead();
Q_INVOKABLE void masterPortWrite(int);

Q_INVOKABLE int alternateIP1Read();
Q_INVOKABLE void alternateIP1Write(int);

Q_INVOKABLE int alternateIP2Read();
Q_INVOKABLE void alternateIP2Write(int);

Q_INVOKABLE int alternateIP3Read();
Q_INVOKABLE void alternateIP3Write(int);

Q_INVOKABLE int alternateIP4Read();
Q_INVOKABLE void alternateIP4Write(int);

Q_INVOKABLE int alternatePortRead();
Q_INVOKABLE void alternatePortWrite(int);

Q_INVOKABLE QString apnRead();
Q_INVOKABLE void apnWrite(QString);

signals:

public slots:
};

#endif // CONCENTRATORINFO_H

这是我定义的一个QList:

QList<ConcentratorInfo> concentratorList;

但是在使用append添加到一个QList是程序就会报错。

concentratorList.append(concentratorStruct);

报如下错误:

1、D:\qt5.4.2\5.4\mingw491_32\include\QtCore\qobject.h:463: error: 'QObject::QObject(const QObject&)' is private
Q_DISABLE_COPY(QObject)
^
2、E:\git\windowopener\src\daemon\ConcentratorInfo.h:7: error: within this context
class ConcentratorInfo : public QObject
^
3、D:\qt5.4.2\5.4\mingw491_32\include\QtCore\qglobal.h:1022: error: 'QObject& QObject::operator=(const QObject&)' is private
Class &operator=(const Class &) Q_DECL_EQ_DELETE;
^
4、E:\git\windowopener\src\daemon\ConcentratorInfo.h:7: error: within this context
class ConcentratorInfo : public QObject

请问这是问什么?
...全文
596 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuwq2015 2015-06-22
  • 打赏
  • 举报
回复
引用 5 楼 dext 的回复:
QList<ConcentratorInfo*>
这样我在使用 QList::appent的时候会报类型错误
dext 2015-06-11
  • 打赏
  • 举报
回复
QList<ConcentratorInfo*>
jiqiang01234 2015-06-10
  • 打赏
  • 举报
回复
Q_DISABLE_COPY ( Class ) Disables the use of copy constructors and assignment operators for the given Class. Instances of subclasses of QObject should not be thought of as values that can be copied or assigned, but as unique identities. This means that when you create your own subclass of QObject (director or indirect), you should not give it a copy constructor or an assignment operator. However, it may not enough to simply omit them from your class, because, if you mistakenly write some code that requires a copy constructor or an assignment operator (it's easy to do), your compiler will thoughtfully create it for you. You must do more. 用QList保存指针,不保存对象
xuwq2015 2015-06-10
  • 打赏
  • 举报
回复
引用 1 楼 jiqiang01234 的回复:
错误提示很明显了,QObject对象不能拷贝(注意:不是指针)
能所明白点吗
xuwq2015 2015-06-10
  • 打赏
  • 举报
回复
那就是说这个类不能继承QObject?
jiqiang01234 2015-06-10
  • 打赏
  • 举报
回复
错误提示很明显了,QObject对象不能拷贝(注意:不是指针)

16,212

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧