Results 1 to 2 of 2

Thread: error ISO C++ forbids declaration of 'obj' with no type

  1. #1
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    44
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default error ISO C++ forbids declaration of 'obj' with no type

    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,SL OT(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:rint(){
    qDebug()<<"running print() in thread";
    }


    can any body please help me with this as everythiing is defined properly
    Life is like a dream, sometimes it is good and somtimes it is bad, but in the end it is over

  2. #2
    Join Date
    Mar 2008
    Location
    Marslev, Denmark
    Posts
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: error ISO C++ forbids declaration of 'obj' with no type

    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"
    ...
    Bo Thorsen, Viking Software
    Qt applications on Linux and Windows

Similar Threads

  1. Replies: 2
    Last Post: 10th October 2010, 16:38
  2. C++ forbids declarations with no type
    By brianc in forum Newbie
    Replies: 3
    Last Post: 5th August 2010, 23:09
  3. Replies: 13
    Last Post: 31st July 2010, 15:19
  4. Replies: 12
    Last Post: 29th April 2010, 13:22
  5. forbids declaration of QHash with no type
    By nina1983 in forum Qt Programming
    Replies: 4
    Last Post: 16th July 2008, 13:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.