[Interest] QExplicitlySharedDataPointer Example

Michael Jackson imikejackson at gmail.com
Thu Jul 18 19:23:19 CEST 2013


Ok, I got a little farther but now when I try to use my class in a program I get some compile errors.

----------------QtFilterTest.h
#include <QtCore/QString>
#include <QtCore/QExplicitlySharedDataPointer>
class SegmentGrainsData;

class SegmentGrains
{
  public:
    SegmentGrains();
    SegmentGrains(const SegmentGrains &other);
 protected:
    QExplicitlySharedDataPointer<SegmentGrainsData> d_ptr;
};

----------------QtFilterTest.cpp
 class SegmentGrainsData : public QSharedData
{
  public:
    SegmentGrainsData() : QSharedData()
    { }

    SegmentGrainsData(const SegmentGrainsData &other)
      : QSharedData(other)
    { }

    ~SegmentGrainsData() { }

    float m_Misorientation;
    QString m_InputFile;
};

SegmentGrains::SegmentGrains() {
  d_ptr = new SegmentGrainsData;}
SegmentGrains::SegmentGrains(const SegmentGrains &other)
  : d_ptr (other.d_ptr){}

-------------------main.cpp
#include "QtFilterTest/QtFilter.h"
int main(int argc, char *argv[])
{
  SegmentGrains sg0;
  return 0;
}


 In file included from /Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest.cpp:38:
In file included from /Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:21:
In file included from /Users/Shared/Toolkits/Qt-4.8.4-Cocoa/include/QtCore/QExplicitlySharedDataPointer:1:
/Users/Shared/Toolkits/Qt-4.8.4-Cocoa/include/QtCore/qshareddata.h:166:57: error: member access into incomplete type 'SegmentGrainsData'
    inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; }
                                                        ^
/Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:26:7: note: in instantiation of member function 'QExplicitlySharedDataPointer<SegmentGrainsData>::~QExplicitlySharedDataPointer' requested here
class SegmentGrains
      ^
/Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:24:7: note: forward declaration of 'SegmentGrainsData'
class SegmentGrainsData;
      ^
1 error generated.



On Jul 18, 2013, at 12:34 PM, "Giuseppe D'Angelo" <dangelog at gmail.com> wrote:

> On 18 July 2013 18:29, Michael Jackson <imikejackson at gmail.com> wrote:
>> class EmployeeData : public QExplicitlySharedDataPointer
> 
> This should be inheriting from QSharedData.
> 
> HTH,
> --
> Giuseppe D'Angelo




More information about the Interest mailing list