[Solved] "The header file 'game.h' doesn't include <QObject>."



  • Hey all, I have a problem I can't figure out. I'm trying to implement slots and signals, but QTcreator is throwing a fit. The error thrown is "Undefined reference to game::playerName(std::string)'" in moc_game.cpp, but I believe it is caused by the lines at the top of the moc (see pasebin below).

    moc_game.cpp; http://pastebin.com/6mpxBKsD (error on line 80)
    game.h: http://pastebin.com/74szJpu6

    I've tried a variety of different things, but I'm unsure what is going wrong. Google led to a few results, but nothing that helped. One thing I saw was that an incorrect .pro file could cause it. Here is mine: http://pastebin.com/z5S1aKZZ

    Hoping someone here can help me out a bit.Thanks for any assistance!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    The error means that you didn't implement playerName. Slots need to be implemented in order to build your class.

    Also since you are using std::string (why not QString ?) as parameter type you'll have to register that custom type.



  • [quote author="SGaist" date="1415136164"]Hi and welcome to devnet,

    The error means that you didn't implement playerName. Slots need to be implemented in order to build your class.

    Also since you are using std::string (why not QString ?) as parameter type you'll have to register that custom type.[/quote]

    I forgot the game:: on my implementation. Thanks for pointing me in the right direction!

    I was using std::string as I was using code that was written before I started using Qt. Thanks for letting me know it doesn't work out of the box there.


  • Lifetime Qt Champion

    You're welcome !

    Have a look at the "Signals and Slots" chapter of Qt's documentation, you'll see how to do it properly.

    Since it's build now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.