Results 1 to 5 of 5

Thread: forbids declaration of QHash with no type

  1. #1
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Red face forbids declaration of QHash with no type

    Dear,

    I'm trying to solve this error... I cannot understand what is going wrong... please help me to solve it ! Probably it is only a stupid syntatical error but I cannot see it...

    Here is the code:

    Qt Code:
    1. #ifndef _STA_SCENARIO_MANOEUVREPLAN_H_
    2. #define _STA_SCENARIO_MANOEUVREPLAN_H_
    3.  
    4. #include "scenarioobject.h"
    5.  
    6. enum StaManoeuvreType
    7. {
    8. STA_MANOEUVRE_DURATION = 1000,
    9. STA_MANOEUVRE_DELTAV = 1001,
    10. STA_MANOEUVRE_V_POSITION = 1002,
    11. STA_MANOEUVRE_R_POSITION = 1003,
    12. STA_MANOEUVRE_V_R_POSITION = 1004,
    13. STA_MANOEUVRE_V_R_DURATION = 1005
    14. };
    15.  
    16. class ScenarioManoeuvre;
    17.  
    18. class ScenarioManoeuvrePlan : public ScenarioObject
    19. {
    20. public:
    21. ScenarioManoeuvrePlan();
    22. ~ScenarioManoeuvrePlan();
    23.  
    24. const QList<ScenarioManoeuvre*>& manoeuvres() const { return m_manoeuvres; }
    25. void setName(QString name){m_name=name;}
    26. void addManoeuvre(ScenarioManoeuvre* manoeuvre);
    27.  
    28. QString name()const {return m_name;}
    29. QList<ScenarioManoeuvre*> manoeuvresList() const{return m_manoeuvres;}
    30. QHash<QString, StaManoeuvreType>* typeMap()const {return hash;}
    31. QHash<QString, QString>* nameMap()const {return hashName;}
    32. QStringList inputsName()const {return inputs;}
    33.  
    34. virtual QTreeWidgetItem* createItemSelf(QTreeWidgetItem* parent);
    35. virtual void createItemContents(QTreeWidgetItem* item);
    36.  
    37. private:
    38. QString m_name;
    39. QList<ScenarioManoeuvre*> m_manoeuvres;
    40. QHash<QString, StaManoeuvreType>* hash;
    41. QHash<QString, QString>* hashName;
    42. QStringList inputs;
    43. };
    44.  
    45. #endif // _STA_SCENARIO_MANOEUVREPLAN_H_
    To copy to clipboard, switch view to plain text mode 
    Thank a lot

    Last edited by jpn; 21st July 2008 at 17:24. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: forbids declaration of QHash with no type

    Please post the error that you see while compiling.

  3. #3
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: forbids declaration of QHash with no type

    ok....

    I solve the problem including:

    Qt Code:
    1. #include<QHash>
    2. #include<QStringList>
    To copy to clipboard, switch view to plain text mode 


    but I have one more question...
    Before I added "hash" and "hashName", I had only QString and QList object in my header file. Why I don't have to include this classes? It worked withouth the declaration
    Qt Code:
    1. #include <QString>
    2. #include <QList>
    To copy to clipboard, switch view to plain text mode 
    Why QHash and QStringList need it?

    Thanks
    Last edited by jpn; 21st July 2008 at 17:26. Reason: missing [code] tags

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 162 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: forbids declaration of QHash with no type

    If you use a (any) Qt-class, in a header you usually need to include its header.

    Exceptions are:
    * if you only use a pointer or reference or return type, a forward declaration is enough.

    Qt Code:
    1. class X
    2. {
    3. QString s; // needs include
    4. QTreeView *tv; // forward decl "class QTreeView;" is enough
    5. QHash<QString,QList<int> > hash; // needs includes for QString, QList and QHash
    6. QString getName() const; // forward declaration enough
    7. };
    To copy to clipboard, switch view to plain text mode 

    Sometimes you get away without including a header, namely if you include other headers that in turn include the header you would need.
    Still, I consider it good practice to explicitly include any header of a class that is explicitly used in a class.

    In your case: QStringList inherits QList. Therefore its header must include the QList-header. Thus you do not have to include it.
    QString is part of QStringList as well.

    HTH

  5. #5
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: forbids declaration of QHash with no type

    Great!

    Now I understand!

    Thank you so much!


Similar Threads

  1. Installation on Fedora Core 4
    By jcr in forum Installation and Deployment
    Replies: 3
    Last Post: 29th January 2009, 01:34
  2. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  3. problem with forward declaration
    By MarkoSan in forum General Programming
    Replies: 14
    Last Post: 6th January 2008, 21:45
  4. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38
  5. Compile Errors
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 05:26

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.