title: Qt / C++ - "Including" a header file causes a LOT of errors (spam)
body: <p>I'm having some problems with my script. Everything was fine for a while but now when I <code>#include</code> a file I get errors that occur on any line pointing to another class. Like these (there's actually 12 of them..):</p>
  
  <p><code>x:\development\inkpuppet\newdialog.h:20: error: C2143: syntax error : missing ';' before '*'</code></p>
  
  <p><code>x:\development\inkpuppet\newdialog.h:20: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int</code></p>
  
  <p>Occurs when I say <code>InkPuppet *pointerToPuppet;</code></p>
  
  <p>Edit: the include I can't put in the header is inkspot.h in the inkpuppet.h header.</p>
  
  <p>For each pointer I get the two above errors x3.</p>
  
  <p>Then I get errors because obviously the pointers no longer work.</p>
  
  <p>I'm going to go ahead and post all my code because I do not know which parts will be relevant.</p>
  
  <p>inkpuppet.h</p>
  
  <pre><code>#ifndef INKPUPPET_H
  #define INKPUPPET_H
  
  #include "inkspot.h"
  //#include "ui_inkpuppet.h"
  
  #include &lt;QMainWindow&gt;
  #include &lt;QWidget&gt;
  
  namespace Ui {
  class InkPuppet;
  }
  
  class InkPuppet : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit InkPuppet(QWidget *parent = 0);
      ~InkPuppet();
  
      Ui::InkPuppet *ui;
  
  private slots:
      void setMinimum(int value);
      void setMaximum(int value);
      void actionNew();
      void actionAbout();
      void setSpacing(int);
      void on_colorAButton_clicked();
  };
  
  #endif // INKPUPPET_H
  </code></pre>
  
  <p>inkpuppet.cpp</p>
  
  <pre><code>#include "inkpuppet.h"
  #include "ui_inkpuppet.h"
  #include "newdialog.h"
  #include "aboutdialog.h"
  #include "inkspot.h"
  
  
  #include &lt;Qt&gt;
  #include &lt;QtCore&gt;
  #include &lt;QtGui&gt;
  #include &lt;QWidget&gt;
  #include &lt;QDialog&gt;
  #include &lt;QMainWindow&gt;
  #include &lt;QDebug&gt;
  #include &lt;QColorDialog&gt;
  
  
  InkPuppet::InkPuppet(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::InkPuppet)
  {
      ui-&gt;setupUi(this);
      //connect the frame range boxes to the timeslider
      connect(ui-&gt;lowerFrameBox, SIGNAL(valueChanged(int)), this, SLOT(setMinimum(int)));
      connect(ui-&gt;upperFrameBox, SIGNAL(valueChanged(int)), this, SLOT(setMaximum(int)));
  
      //connect tool palette items
      connect(ui-&gt;spacingBox, SIGNAL(valueChanged(int)), this, SLOT(setSpacing(int)));
  
      connect(ui-&gt;colorAButton, SIGNAL(clicked()), this, SLOT(on_colorAButton_clicked()));
  
      //connect the menu items
      connect(ui-&gt;actionNew, SIGNAL(triggered()), this, SLOT(actionNew()));
      connect(ui-&gt;actionAbout, SIGNAL(triggered()), this, SLOT(actionAbout()));
  
  }
  
  void InkPuppet::setMinimum(int value)
  {
      ui-&gt;timeSlider-&gt;setMinimum(value);
      ui-&gt;frameNumberBox-&gt;setMinimum(value);
  }
  
  void InkPuppet::setMaximum(int value)
  {
      ui-&gt;timeSlider-&gt;setMaximum(value);
      ui-&gt;frameNumberBox-&gt;setMaximum(value);
  }
  
  
  void InkPuppet::setSpacing(int)
  {
      InkSpot *spot = new InkSpot(this);
      //spot-&gt;puppet = this;
      spot-&gt;spacing = ui-&gt;spacingBox-&gt;value();
  }
  
  //menu items
  void InkPuppet::actionNew()
  {
      NewDialog *nDialog = new NewDialog;
      //nDialog-&gt;createNew(this);
      nDialog-&gt;pointerToPuppet = this;
      nDialog-&gt;setModal(true);
  
      nDialog-&gt;show();
  
  }
  
  void InkPuppet::actionAbout()
  {
      AboutDialog *aDialog = new AboutDialog;
      aDialog-&gt;setModal(true);
      aDialog-&gt;show();
  }
  
  
  //tool menu
  void InkPuppet::on_colorAButton_clicked()
  {
  //    QColor color = QColorDialog(QColor-&gt;setRgb(255, 0, 0));
  //    //color-&gt;setRgb(0, 0, 0);
  //    qDebug() &lt;&lt; "done";
  //    if(color-&gt;isValid())
  //    {
  
  //        QString qss = QString("background-color: %1").arg(color-&gt;name());
  //        ui-&gt;colorAButton-&gt;setStyleSheet(qss);
  //    }
  }
  
  
  InkPuppet::~InkPuppet()
  {
      delete ui;
  }
  </code></pre>
  
  <p>inkspot.h</p>
  
  <pre><code>#ifndef INKSPOT_H
  #define INKSPOT_H
  
  #include "newdialog.h"
  //#include "inkpuppet.h"
  
  #include &lt;QObject&gt;
  #include &lt;QWidget&gt;
  #include &lt;QPainter&gt;
  #include &lt;QPaintEvent&gt;
  #include &lt;QLabel&gt;
  #include &lt;QPoint&gt;
  #include &lt;QImage&gt;
  
  
  namespace Ui {
  class InkSpot;
  }
  
  class InkSpot : public QWidget
  {
      Q_OBJECT
  public:
      explicit InkSpot(QWidget *parent = 0);
      void draw(QPainter *painter);
      QWidget *widget;
      int canvasWidth;
      int canvasHeight;
      float spacing;
      NewDialog *newDialog;
      QPixmap pixmap;
  
  signals:
      //int sendWidthOfCanvas();
      //void sendHeightOfCanvas();
  
  public slots:
      //void widthOfCanvas();
      //void heightOfCanvas();
  
  protected:
      void mousePressEvent(QMouseEvent *event);
      void mouseMoveEvent(QMouseEvent *event);
      void mouseReleaseEvent(QMouseEvent *event);
      void paintEvent(QPaintEvent *event);
  
  
  private:
      void drawLineTo(const QPoint &amp;endPoint);
      bool drawing;
      QPoint lastPoint;
      QImage image;
      QImage test2;
  
  
      Ui::InkSpot *ui;
  
  };
  
  #endif // INKSPOT_H
  </code></pre>
  
  <p>inkspot.cpp</p>
  
  <pre><code>#include "inkspot.h"
  #include "inkpuppet.h"
  #include "ui_inkpuppet.h"
  
  #include "newdialog.h"
  #include "ui_newdialog.h"
  
  #include &lt;QtCore&gt;
  #include &lt;QtGui&gt;
  #include &lt;QWidget&gt;
  #include &lt;QPainter&gt;
  #include &lt;QPaintEvent&gt;
  
  InkSpot::InkSpot(QWidget *parent) :
      QWidget(parent)
  {
      widget = this;
      drawing = false;
      //spacing = puppet-&gt;ui-&gt;spacingBox-&gt;value();
      spacing = 1;//puppet-&gt;ui-&gt;spacingBox-&gt;value();
  }
  
  void InkSpot::mousePressEvent(QMouseEvent *event)
  {
      if(event-&gt;button() == Qt::LeftButton)
      {
          lastPoint = event-&gt;pos();
          drawing = true;
      }
  }
  
  void InkSpot::mouseMoveEvent(QMouseEvent *event)
  {
      if((event-&gt;buttons() &amp; Qt::LeftButton) &amp;&amp; drawing)
      {
          drawLineTo(event-&gt;pos());
      }
  }
  
  void InkSpot::mouseReleaseEvent(QMouseEvent *event)
  {
      if(event-&gt;button() == Qt::LeftButton &amp;&amp; drawing)
      {
          drawLineTo(event-&gt;pos());
          drawing = false;
      }
  }
  
  void InkSpot::drawLineTo(const QPoint &amp;endPoint)
  {
      QPainter painter(&amp;pixmap);
      painter.setPen(Qt::NoPen);
      painter.setBrush(Qt::NoBrush);
  
      QFile *stencilInput; // file for input, assumes a SQUARE RAW 8 bit grayscale image, no JPG no GIF, no size/format header, just 8 bit values in the file
      char *brushPrototype; // raw brush prototype
      uchar *brushData; // raw brush data
  
      stencilInput = new QFile("C:/brush3.raw");  // open raw file
      stencilInput-&gt;open(QIODevice::ReadOnly);
      QDataStream in;
      in.setDevice(stencilInput);
      int size = stencilInput-&gt;size();  // set size to the length of the raw file
  
      brushPrototype = new char[size];  // create the brush prototype array
      in.readRawData(brushPrototype, size);  // read the file into the prototype
      brushData = new uchar[size];  // create the uchar array you need to construct QImage
  
      for (int i = 0; i &lt; size; ++i)
          brushData[i] = (uchar)brushPrototype[i];  // copy the char to the uchar array
  
      QImage test(brushData, 128, 128, QImage::Format_Indexed8); // create QImage from the brush data array
       // 128x128 was my raw file, for any file size just use the square root of the size variable provided it is SQUARE
      QImage test2(128, 128, QImage::Format_ARGB32);
  
  
     QVector&lt;QRgb&gt; vectorColors(256);  // create a color table for the image
      for (int c = 0; c &lt; 256; c++)
          vectorColors[c] = qRgb(c, c, c);
  
      test.setColorTable(vectorColors);  // set the color table to the image
  
      for (int iX = 0; iX &lt; 128; ++iX)  // fill all pixels with 255 0 0 (red) with random variations for OIL PAINT effect
      // use your color of choice and remove random stuff for solid color
      // the fourth parameter of setPixel is the ALPHA, use that to make your brush transparent by multiplying by opacity 0 to 1
      {
          for (int iY = 0; iY &lt; 128; ++iY)
          {
              test2.setPixel(iX, iY, qRgba(255, 100, 100, (255-qGray(test.pixel(iX, iY)))*0.5));
          }
      }
      // final convertions of the stencil and color brush
      QPixmap testPixmap = QPixmap::fromImage(test2);
      QPixmap testPixmap2 = QPixmap::fromImage(test);
  
      painter.setBrush(Qt::NoBrush);
      painter.setPen(Qt::NoPen);
      // in a paint event you can test out both pixmaps
  //    QLineF line = QLineF(lastPoint, endPoint);
  //    float lineLength = line.length();
  //    qDebug() &lt;&lt; line.length();
  //    line.setLength(100.01f);
  //    qDebug() &lt;&lt; line.length();
  
      QPainterPath path = QPainterPath(lastPoint);
      path.lineTo(endPoint);
      //qDebug() &lt;&lt; path.currentPosition();
      //qDebug() &lt;&lt; path.length();
      qreal length = path.length();
      qreal pos = 0;
  
      while (pos &lt; length)
      {
          qreal percent = path.percentAtLength(pos);
          painter.drawPixmap(path.pointAtPercent(percent).x() - 16, path.pointAtPercent(percent).y() - 16, 32, 32, testPixmap);
          pos += spacing;
      }
  
  
      //painter.drawPixmap(line.p1().x() - 16, line.p1().y() - 16, 32, 32, testPixmap);
  
      //delete all dynamically allocated objects with no parents
      delete [] brushPrototype;
      delete [] brushData;
      delete stencilInput;
  
  
      lastPoint = endPoint;
  
  }
  
  
  void InkSpot::paintEvent(QPaintEvent *event)
  {
      QPainter painter(this);
      painter.setPen(Qt::NoPen);
      painter.setBrush(Qt::NoBrush);
      QRect rect = event-&gt;rect();
      painter.drawPixmap(rect, pixmap, rect);
  
      qDebug() &lt;&lt; spacing;
  
      update();
  
  }
  </code></pre>
  
  <p>newdialog.h</p>
  
  <pre><code>#ifndef NEWDIALOG_H
  #define NEWDIALOG_H
  
  //#include "ui_newdialog.h"
  #include "inkpuppet.h"
  
  #include &lt;QDialog&gt;
  
  namespace Ui {
  class NewDialog;
  }
  
  class NewDialog : public QDialog
  {
      Q_OBJECT
  
  public:
      explicit NewDialog(QWidget *parent = 0);
      ~NewDialog();
      InkPuppet *pointerToPuppet;
      Ui::NewDialog *ui;
  
  public slots:
      //void createNew(InkPuppet *existingPuppet);
      void createNew();
  
  };
  
  #endif // NEWDIALOG_H
  </code></pre>
  
  <p>newdialog.cpp</p>
  
  <pre><code>#include "newdialog.h"
  #include "ui_newdialog.h"
  #include "inkpuppet.h"
  #include "ui_inkpuppet.h"
  #include "inkspot.h"
  
  
  #include &lt;QDebug&gt;
  #include &lt;QSignalMapper&gt;
  #include &lt;QObject&gt;
  #include &lt;QtOpenGL/QGLWidget&gt;
  
  
  NewDialog::NewDialog(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::NewDialog)
  {
      ui-&gt;setupUi(this);
  
      connect(ui-&gt;buttonBox, SIGNAL(accepted()), SLOT(createNew()));
      //connect(ui-&gt;buttonBox, SIGNAL(accepted()), SLOT(createNew(InkPuppet*)));
  
  }
  
  void NewDialog::createNew()
  {
      InkSpot *ink;
      ink = new InkSpot();
      ink-&gt;newDialog = this;
      pointerToPuppet-&gt;ui-&gt;canvas-&gt;addWidget(ink-&gt;widget);
      //QSize size = pointerToPuppet-&gt;ui-&gt;canvas-&gt;sizeHint();
      ink-&gt;widget-&gt;resize(ui-&gt;widthBox-&gt;value(), ui-&gt;heightBox-&gt;value());
      pointerToPuppet-&gt;ui-&gt;scrollCanvasItems-&gt;resize(ui-&gt;widthBox-&gt;value(), ui-&gt;heightBox-&gt;value());
      //pointerToPuppet-&gt;ui-&gt;canvas-&gt;setAlignment(ink-&gt;widget, Qt::AlignAbsolute);
      ink-&gt;pixmap = QPixmap(QSize(ui-&gt;widthBox-&gt;value(), ui-&gt;heightBox-&gt;value()));
      close();
  }
  
  NewDialog::~NewDialog()
  {
      delete ui;
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "inkpuppet.h"
  #include "inkspot.h"
  #include "newdialog.h"
  #include "aboutdialog.h"
  #include &lt;QApplication&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      InkPuppet w;
      w.show();
  
      return a.exec();
  }
  </code></pre>