PDA

View Full Version : error ISO C++ forbids declaration of 'obj' with no type



naturalpsychic
26th January 2011, 03:48
file.h:

#ifndef FILE_H
#define FILE_H

#include <QObject>
#include "fthread.h"
class File : public QObject
{
Q_OBJECT
public:
File(QObject *parent = 0);
FThread *thread; /// <<------------------ here is error
void test();


};

#endif // FILE_H

fthread.h

#ifndef FTHREAD_H
#define FTHREAD_H

#include <QThread>
#include "file.h"


class FThread : public QThread
{
Q_OBJECT
public:


explicit FThread(QObject *parent = 0);
virtual void run();
File *f;
signals:
void done();
public slots: //basically suppose to be in file.h
void print();
};

#endif // FTHREAD_H

file.cpp


#include "file.h"
#include <QDebug>
File::File(QObject *parent) :
QObject(parent)
{

QObject::connect(&thread,SIGNAL(done()),&thread,SLOT(print()),Qt::QueuedConnection);

}
void File::test(){
qDebug()<<"in test process";
emit thread->done();
}

fthread.cpp



#include "fthread.h"
#include <QDebug>

FThread::FThread(QObject *parent) :
QThread(parent)
{
}

void FThread::run(){
f->test();
}
void FThread::print(){
qDebug()<<"running print() in thread";
}


can any body please help me with this as everythiing is defined properly

bothorsen
26th January 2011, 06:23
This is a beginners C++ problem and has nothing to do with Qt.

fhtread.h includes file.h and file.h includes fthread.h, and you can't do that. You can only do one way.

The proper solution in this case is to not include the other at all, but instead to declare the class. Like this:

file.h:

#ifndef FILE_H
#define FILE_H

#include <QObject>

class FThread;

class File : public QObject
{
Q_OBJECT
public:
File(QObject *parent = 0);
FThread *thread; /// <<------------------ here is error
void test();


};

#endif // FILE_H



file.cpp:


#include "file.h"
#include "fthread.h"
...