There are two solutions for this issue, but your concrete issue may boil down to the same root cause which is to put the header file in question into the HEADERS
variable. Having done this, you may need to make sure to reissue the qmake
command.
Based on your question, it is not clear that it will do the job on its own since we have not seen neither your build system, nor the source file, but:
1) Make the build system take care of the issue. This looks simpler at first.
2) Use #include "foo.moc"
in the end of the source file to avoid it. This version will work with any build system in the same way once the moc file is generated.