PDA

View Full Version : QMap error



afflictedd2
8th April 2009, 19:57
Hi everyone,

I created a map
QMap<QString, VelocityModel> vmMap;

I try to do this, to retrieve a VelocityModel object.

vmMap.value(key);

but I get this error:

c:/Qt/4.4.3/include/QtCore/../../src/corelib/tools/qmap.h:438: error: no matching function for call to `VelocityModel::VelocityModel()'
velocitymodel.h:7: note: candidates are: VelocityModel::VelocityModel(const VelocityModel&)
velocitymodel.h:10: note: VelocityModel::VelocityModel(QString, QString)

The only constructor I have is this one:
VelocityModel::VelocityModel (QString modelName, QString modelFile )


#include <QtGui>
#include "velocitymodel.h"

VelocityModel::VelocityModel (QString modelName, QString modelFile ) : mModelName( modelName ), mModelFile( modelFile ) {}
QString VelocityModel::modelName() const { return mModelName; }
QString VelocityModel::modelFile() const { return mModelFile; }



#ifndef _VELOCITYMODEL_H_
#define _VELOCITYMODEL_H_

#include <QString>
#include <QStringList>

class VelocityModel {

public:
VelocityModel ( QString modelName, QString modelFile );
QString modelName() const;
QString modelFile() const;

private:
QString mModelName;
QString mModelFile;
QStringList velocities;
};

#endif /* _VELOCITYMODEL_H_ */

Is there something I need to declare in my velocitymodel class, in order to retrieve the object?

Sheng
8th April 2009, 20:02
you need to define a default constructor in your class.

lni
8th April 2009, 20:08
value() method is from iterator, to get from map, change to:
vmMap.value(key) => vmMap[ key ]

lni
8th April 2009, 20:10
value() method is from iterator, to get from map, change to:
vmMap.value(key) => vmMap[ key ]

Sorry, I was wrong, just did as Sheng pointed out

afflictedd2
8th April 2009, 20:30
I can't believe that was it O_o and empty default constructor :\

Thank you all.