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 :confused: ! Probably it is only a stupid syntatical error but I cannot see it...
Here is the code:
Code:
#ifndef _STA_SCENARIO_MANOEUVREPLAN_H_
#define _STA_SCENARIO_MANOEUVREPLAN_H_
#include "scenarioobject.h"
enum StaManoeuvreType
{
STA_MANOEUVRE_DURATION = 1000,
STA_MANOEUVRE_DELTAV = 1001,
STA_MANOEUVRE_V_POSITION = 1002,
STA_MANOEUVRE_R_POSITION = 1003,
STA_MANOEUVRE_V_R_POSITION = 1004,
STA_MANOEUVRE_V_R_DURATION = 1005
};
class ScenarioManoeuvre;
class ScenarioManoeuvrePlan : public ScenarioObject
{
public:
ScenarioManoeuvrePlan();
~ScenarioManoeuvrePlan();
const QList<ScenarioManoeuvre*>& manoeuvres() const { return m_manoeuvres; }
void setName
(QString name
){m_name
=name;
} void addManoeuvre(ScenarioManoeuvre* manoeuvre);
QString name
()const {return m_name;
} QList<ScenarioManoeuvre*> manoeuvresList() const{return m_manoeuvres;}
QHash<QString, StaManoeuvreType>* typeMap()const {return hash;}
QHash<QString, QString>* nameMap()const {return hashName;}
private:
QList<ScenarioManoeuvre*> m_manoeuvres;
QHash<QString, StaManoeuvreType>* hash;
QHash<QString, QString>* hashName;
};
#endif // _STA_SCENARIO_MANOEUVREPLAN_H_
Thank a lot
:D
Re: forbids declaration of QHash with no type
Please post the error that you see while compiling.
Re: forbids declaration of QHash with no type
ok....
I solve the problem including:
Code:
#include<QHash>
#include<QStringList>
;)
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
Code:
#include <QString>
#include <QList>
Why QHash and QStringList need it?
Thanks
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.
Code:
class X
{
QTreeView *tv;
// forward decl "class QTreeView;" is enough QHash<QString,QList<int> > hash; // needs includes for QString, QList and QHash
QString getName
() const;
// forward declaration enough };
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
Re: forbids declaration of QHash with no type
Great!
Now I understand!
Thank you so much!
:D