PDA

View Full Version : forbids declaration of QHash with no type



nina1983
16th July 2008, 12:42
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:


#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;}
QStringList inputsName()const {return inputs;}

virtual QTreeWidgetItem* createItemSelf(QTreeWidgetItem* parent);
virtual void createItemContents(QTreeWidgetItem* item);

private:
QString m_name;
QList<ScenarioManoeuvre*> m_manoeuvres;
QHash<QString, StaManoeuvreType>* hash;
QHash<QString, QString>* hashName;
QStringList inputs;
};

#endif // _STA_SCENARIO_MANOEUVREPLAN_H_

Thank a lot

:D

munna
16th July 2008, 12:51
Please post the error that you see while compiling.

nina1983
16th July 2008, 12:51
ok....

I solve the problem including:


#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

#include <QString>
#include <QList>

Why QHash and QStringList need it?

Thanks

caduel
16th July 2008, 13:00
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.


class X
{
QString s; // needs include
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

nina1983
16th July 2008, 13:05
Great!

Now I understand!

Thank you so much!

:D