When using Qt Creator:
Warning: Do not do this if you already have a .pro file - you'll lose it!
In order to automatically ensure that all moc cpp files are generated, you can get qmake to automatically generate a .pro file for you instead of writing one yourself.
Run
qmake -project
in the project directory, and qmake will scan your directory for all C++ headers and source files to generate moc cpp files for.
The problem is almost certainly that you are not compiling or not linking in the generated moc_AddressBook.cpp file. (It should have been generated for you -- you are running Qt's moc
on your code before compiling, right?)
To answer a little more thoroughly, the Q_OBJECT
macro signals Qt's moc
tool to create an extra implementation file that contains the code necessary to support QObject
's meta-information system. If you had any signals or slots, it would do a few things for those as well.
An alternative solution might be to remove the Q_OBJECT
macro. You probably don't want to do this, but it would help the immediate problem, and it isn't strictly necessary with the code that you've presented.
Also, I would note that your line:
#include "addressbook.h"
Should probably be:
#include "AddressBook.h"
based on how you presented the filenames in the question.
Assuming you are using qmake to generate your Makefile, be sure that AddressBook.h is specified in your .pro file's HEADERS's variable, e.g.
HEADERS = AddressBook.h
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With