Error on build..QThread class
I'm working on my multi-threaded project and got this error on build. I did not require any initialization with my threads and I just made an instance of the thread in the private section of my QMainWindow.
error: field 'capturingThread' has incomplete type
error: field 'computingThread' has incomplete type
The following code is my main window and the error points to the private section here.
Code:
#ifndef GENIUS_H
#define GENIUS_H
#include <QMainWindow>
#include "ui_genius.h"
class CapturingThread;
class ComputingThread;
class GeniusMain
: public QMainWindow,
private Ui
::genius{
Q_OBJECT
public:
protected:
private slots:
void standbyThreads();
void startTransmission();
void haltThreads();
void printFPS();
void printDistance();
void printTeam();
void printOpp();
private:
CapturingThread capturingThread;
ComputingThread computingThread;
};
#endif
Here are the header files for my threads capturingThread and computingThread.
Code:
#ifndef CAPTURINGTHREAD_H
#define CAPTURINGTHREAD_H
#include <QThread>
class ImageBuffer;
class CapturingThread
: public QThread {
public:
CapturingThread();
~CapturingThread();
void haltCapture();
protected:
void run();
private:
volatile bool halt;
ImageBuffer* imageBuffer;
};
#endif
Code:
#ifndef COMPUTINGTHREAD_H
#define COMPUTINGTHREAD_H
#include <QThread>
class ImageBuffer;
class ComputingThread
: public QThread{
public:
ComputingThread();
~ComputingThread();
void haltComputing();
void startTransmitting();
void stopTransmitting();
protected:
void run();
private:
volatile bool halt;
volatile bool transmit;
ImageBuffer* imageBuffer;
};
#endif
What could be the source of the build error?
Re: Error on build..QThread class
My guess would be that forward declaration i.e. code below:
Code:
class CapturingThread;
class ComputingThread;
Works for pointers but not for objects (see code below).
Code:
private:
CapturingThread capturingThread;
ComputingThread computingThread;
So either include both header files (computingthread.h / capturingthread.h) in genius.h file or use next piece of code:
Code:
private:
CapturingThread *capturingThread;
ComputingThread *computingThread;
And then allocate the memory for those objects when you need them.