Results 1 to 5 of 5

Thread: QMap error

  1. #1
    Join Date
    Jul 2008
    Posts
    48
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QMap error

    Hi everyone,

    I created a map
    Qt Code:
    1. QMap<QString, VelocityModel> vmMap;
    To copy to clipboard, switch view to plain text mode 

    I try to do this, to retrieve a VelocityModel object.
    Qt Code:
    1. vmMap.value(key);
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. VelocityModel::VelocityModel (QString modelName, QString modelFile )
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QtGui>
    2. #include "velocitymodel.h"
    3.  
    4. VelocityModel::VelocityModel (QString modelName, QString modelFile ) : mModelName( modelName ), mModelFile( modelFile ) {}
    5. QString VelocityModel::modelName() const { return mModelName; }
    6. QString VelocityModel::modelFile() const { return mModelFile; }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef _VELOCITYMODEL_H_
    2. #define _VELOCITYMODEL_H_
    3.  
    4. #include <QString>
    5. #include <QStringList>
    6.  
    7. class VelocityModel {
    8.  
    9. public:
    10. VelocityModel ( QString modelName, QString modelFile );
    11. QString modelName() const;
    12. QString modelFile() const;
    13.  
    14. private:
    15. QString mModelName;
    16. QString mModelFile;
    17. QStringList velocities;
    18. };
    19.  
    20. #endif /* _VELOCITYMODEL_H_ */
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QMap error

    you need to define a default constructor in your class.

  3. The following user says thank you to Sheng for this useful post:

    afflictedd2 (8th April 2009)

  4. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QMap error

    value() method is from iterator, to get from map, change to:
    vmMap.value(key) => vmMap[ key ]

  5. The following user says thank you to lni for this useful post:

    afflictedd2 (8th April 2009)

  6. #4
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QMap error

    Quote Originally Posted by lni View Post
    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

  7. The following user says thank you to lni for this useful post:

    afflictedd2 (8th April 2009)

  8. #5
    Join Date
    Jul 2008
    Posts
    48
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QMap error

    I can't believe that was it O_o and empty default constructor :\

    Thank you all.

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  4. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  5. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31

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.