PDA

View Full Version : Error on build..QThread class



freekill
19th November 2009, 02:31
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.


#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:
GeniusMain(QMainWindow *parent);

protected:
void closeEvent (QCloseEvent *event);

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.


#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




#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?

tsp
19th November 2009, 05:45
My guess would be that forward declaration i.e. code below:


class CapturingThread;
class ComputingThread;


Works for pointers but not for objects (see code below).


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:


private:
CapturingThread *capturingThread;
ComputingThread *computingThread;


And then allocate the memory for those objects when you need them.