0

I been trying and trying to get this to work but it just refuses to work. I read the QT documentation and I'm just unable to get the insert function to function. When I build I get the 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 for call to '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 is the 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 the implementation

SDStreamEmbed::SDStreamEmbed() {

}

SDStreamEmbed::SDStreamEmbed(const SDStreamEmbed& other) {

}

QString SDStreamEmbed::FriendlyName() const {
    return friendlyName;
}

and how I am invoking it

SDChatEmbed embedTest();
ChatEmbeds.insert("DemoTest", embedTest);

and the definition of ChatEmbeds

QHash<QString, SDStreamEmbed> StreamEmbeds;
DrHouse
  • 99
  • 1
  • 8

1 Answers1

3

Replace:

SDChatEmbed embedTest();

with:

SDChatEmbed embedTest;

The compiler interprets the first line as a function declaration. This is visible in the error message: it deduces the following type for the second argument:

SDChatEmbed (&)()

and that's a function signature.

I don't think you need an explicit QString cast/construction for the first argument since QString has a constructor that takes a const char*, so that one should get converted automatically.

(See here for some interesting info.)

Community
  • 1
  • 1
Mat
  • 202,337
  • 40
  • 393
  • 406
  • OHHH wow, its always the most simple syntax stuff that makes it fail. Thank you, would have took me hours and I'd still not think of that, being from a C# background C++ is a bit confusing at times. And thanks for the additional information to help me understand why its like that, very helpful. – DrHouse Oct 06 '11 at 10:03