Here is a simple example for my problem:
// test.h
#include <QObject>
#include <vtkSmartPointer.h>
class vtkImageData;
class test : public QObject
{
private:
vtkSmartPointer<vtkImageData> img = vtkSmartPointer<vtkImageData>::New();
public:
test(/* args */) = default;
~test() =default;
};
// test.cxx
#include "test.h"
#include "vtkImageData.h"
Everything works fine with above code, however, if I add a Q_OBJECT
macro to test
class:
class test : public QObject
{
Q_OBJECT
private:
vtkSmartPointer<vtkImageData> img = vtkSmartPointer<vtkImageData>::New();
public:
test(/* args */) = default;
~test() =default;
};
the compiler will produce an error:incomplete type 'vtkImageData' used in nested name specifier
.
It looks like an issue due to Qt moc mechanism. Here are my questions:
- What exactly causes this kind of problem?
- Is there a way to use forward declaration with
Q_OBJECT
? Or I can only include the header file whenQ_OBJECT
macro is used?