类继承自QObject

时间:2018-01-23 12:36:53

标签: c++ qt

我遇到了从QObject继承的类的问题。我的问题是我希望我的类queueTcp从QQueue继承,所以我可以添加另一个类commandTcp的对象。一切正常,直到我让commandTcp继承QObject。

当我尝试编译时,我得到11个错误,如:

  

使用已删除的函数'QObject :: QObject(const QObject&)

     

QObject :: QObject(const QObject&)'是私有的

我试着在最后几天找出它们,但找不到任何适用于我的解决方案。

我的代码是:

queueTcp.h

#ifndef QUEUETCP_H
#define QUEUETCP_H

#include <QObject>
#include <commandtcp.h>
#include <QQueue>

class queueTcp: public QObject, public QQueue<commandTcp>
{
Q_OBJECT

public:
    queueTcp();
    void newCommand();
};

#endif // QUEUETCP_H

commandTcp.h

#ifndef COMMANDTCP_H
#define COMMANDTCP_H

#include <QObject>
#include <QByteArray>

class commandTcp: public QObject
{
Q_OBJECT

private:
    QByteArray storeCommand;
    int arraySize;
    int destinationAddress;
    int length;
    int command;

public:
    commandTcp(int, int, int, QByteArray, int);
};

#endif // COMMANDTCP_H

queueTcp.cpp

#include "queuetcp.h"

queueTcp::queueTcp() {

}


void queueTcp::newCommand() {
    commandTcp temp(63, 8, 208, 0, 1);
    this->enqueue(temp);
}

commandTcp.cpp

#include "commandtcp.h"


commandTcp::commandTcp(int _destinationAddress, int _length, int _command, QByteArray _userData, int _arraySize)
{
    arraySize = _arraySize;
    storeCommand = {0};
    storeCommand.append(_userData);
    destinationAddress = _destinationAddress;
    length = _length;
    command = _command;
}

我的问题在哪里? 提前谢谢。

0 个答案:

没有答案