c++ - Issue with QHash -


i been trying , trying work refuses work. read qt documentation , i'm unable insert function function. when build following complication errors

/home/mmanley/projects/streamdesk/libstreamdesk/sddatabase.cpp: in constructor 'sddatabase::sddatabase()': /home/mmanley/projects/streamdesk/libstreamdesk/sddatabase.cpp:27:44: error: no matching function call 'qhash<qstring, sdchatembed>::insert(const char [9], sdchatembed (&)())' /usr/include/qt4/qtcore/qhash.h:751:52: note: candidate is: qhash<key, t>::iterator         qhash<key, t>::insert(const key&, const t&) [with key = qstring, t = sdchatembed] make[2]: *** [libstreamdesk/cmakefiles/streamdesk.dir/sddatabase.cpp.o] error 1 make[1]: *** [libstreamdesk/cmakefiles/streamdesk.dir/all] error 2 

here header file:

class sdstreamembed {         q_object     public:         sdstreamembed();         sdstreamembed(const sdstreamembed &other);          qstring friendlyname() const;          sdstreamembed &operator=(const sdstreamembed &other) {return *this;}         bool operator==(const sdstreamembed &other) const {return friendlyname == other.friendlyname;}      private:         qstring friendlyname; };  q_declare_metatype(sdstreamembed)  inline uint qhash(const sdstreamembed &key) {     return qhash(key.friendlyname()); } 

and implementation

sdstreamembed::sdstreamembed() {  }  sdstreamembed::sdstreamembed(const sdstreamembed& other) {  }  qstring sdstreamembed::friendlyname() const {     return friendlyname; } 

and how invoking it

sdchatembed embedtest(); chatembeds.insert("demotest", embedtest); 

and definition of chatembeds

qhash<qstring, sdstreamembed> streamembeds; 

replace:

sdchatembed embedtest(); 

with:

sdchatembed embedtest; 

the compiler interprets first line function declaration. visible in error message: deduces following type second argument:

sdchatembed (&)() 

and that's function signature.

i don't think need explicit qstring cast/construction first argument since qstring has constructor takes const char*, 1 should converted automatically.

(see here interesting info.)


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -