qt - QObject::QObject(QObject Parent=0) 在此上下文中是私有(private)的

标签 qt private qobject

我有一个名为网格的类。我想跟踪它的对象。所以每当有新的 网格创建完毕,我想要一个信号。我已经添加了

class mesh: public QObject

并将所有方法作为槽并将信号添加到 c-tor 网格创建中。但从 我多年的痛苦就从这里开始了。不管怎样,标题中的错误开始了 出现。甚至认为我评论了所有行,即在每行之前添加 // 在代码中,它仍然说同样的事情。我该如何解决这个问题?

实际代码

#ifndef mesh_H
#define mesh_H

#include <QObject>
#include "mvert.h"
#include "medge.h"
#include "mface.h"

#include <QList>
#include <QString>
#include <QDebug>
#include "glmaterial.h"

class mesh : public QObject
{
    Q_OBJECT
public:
    explicit mesh(QObject *parent = 0);
    QString getName();

private:
    QString Name;
    GLMaterial material;

    QList<MVert> VertList;
    QList<MEdge> EdgeList;
    QList<MFace> FaceList;

    MVert Centroid;

    QList<int> QFaces;
    QList<int> TFaces;

public slots:
    void setName(QString Name);
    void ReadmeshData(QString meshsrc);
    void displayVerts();
    void displayEdges();
    void displayFaces();
    void addVert(MVert vert);
    void addEdge(MEdge edge);
    void addFace(MFace face);
    void removeDoubles();
    MVert generateCentroid();
    //FIXUS
    void sortQandT();
    void reorderFaces();
    void subDivFace(int index, int res);
    void forcedTriangulate();
    //FIXUS
    bool isVertInEdge(MVert input, MEdge edg);
    bool similarVerts(int i,int j);

    QList<int> relatedFacesToVert(MVert input);
    QList<int> relatedEdgesToVert(MVert input);
    QList<int> relatedVertsToVert(MVert input);
    QList<int> relatedFacesToEdge(MEdge input);
    QList<int> relatedEdgesToEdge(MEdge input);
    QList<int> relatedEdgesToFace(MFace input);
    QList<int> relatedFacesToFace(MFace input);

    QList<MVert> reducedVList();

    QList<MVert> vlistInstance();

    MVert midPointOfEdge(int i);
    MVert centroidOfFace(int i);

    mesh operator=(mesh input);

    void GLdraw();

signals:
    void meshCreated(mesh *mesh);

};

最佳答案

产生此错误的行是:

mesh operator=(mesh input);

派生自 QObject 的类不允许有复制构造函数。作为QObject文档说明:

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 in a private section with the macro Q_DISABLE_COPY(). In fact, all Qt classes derived from QObject (direct or indirect) use this macro to declare their copy constructor and assignment operator to be private. The reasoning is found in the discussion on Identity vs Value on the Qt Object Model page. The main consequence is that you should use pointers to QObject (or to your QObject subclass) where you might otherwise be tempted to use your QObject subclass as a value. For example, without a copy constructor, you can't use a subclass of QObject as the value to be stored in one of the container classes. You must store pointers.

如果您想跟踪创建的mesh您可以使用的对象,例如 QList<mesh*>来自您的其他类(class)之一。创建对象后,将其推送到列表等。

关于qt - QObject::QObject(QObject Parent=0) 在此上下文中是私有(private)的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9239097/

相关文章:

c++ - svg 图标在高 DPI 上出现像素化

dart - Dart 如何在幕后实现图书馆隐私?

c++ - QObject::connect 和模板导致问题

c++ - 在多个 Qmenu 中重用一个 QMenu

qt - Qt 中的多种配置

linux - qmake 在 linux 上使用不正确的 Qt 安装路径

c++ - 为 QTreeWidget 的标题设置文本的方法是什么?

c++ - 私有(private)/保护变量 "error: within this context"

c# - 如何在 WPF 中将控件标记为 'Private'?

c++ - 如果从 QObject 派生的类的构造函数抛出,是否会发出 destroyed()?