following is a very simple script that scans  a directory recursively
for .h files that contain 'Q_OBJECT' and then runs moc.exe on them,
generating a moc_filename.h in the same folder. the arguments to 
moc can be provided as well, so you just need to add the call to
the python script as a prebuild event in msvc, add an #include "moc_filename.h" 
to your corresponding .cpp file, and all should be well. Click on the text to 
download the file.

"""AutoMoc.py by J at dynamica.org, options:
-e extension    look for files with this extension
-d directory    start searching in this driectory
-a filename     read the arguments to moc.exe in this file
-r              search subfolders
-h              print this help"""

import os,sys, getopt

directory = ""
files = []
recursive = 0
extension = ".h"
arguments = ""

try:
    opts, args = getopt.getopt( sys.argv[1:], "rha:e:d:" )
except getopt.GetoptError:
    print __doc__
    sys.exit() 
for opt, arg in opts:
    if opt == '-e':
        extension = arg
    elif opt == '-d':
        directory = arg
    elif opt == "-a":
        fp = open( arg, 'r' )
        arguments = fp.read()
        fp.close()
    elif opt == '-r':
        recursive = 1
    else :
        print __doc__
        sys.exit()                  

def walk( directory, call ):   
    directory = os.path.abspath( directory )
    for file in [ file for file in os.listdir( directory ) if not file in [".",".."] ]:
        nfile = os.path.join( directory, file )
        if os.path.isdir( nfile ) and recursive:
            walk( nfile, call )
        elif nfile[-len(extension):] == extension:
            fp = open( nfile, 'r' )
            text = fp.read()
            fp.close()
            if text.find( "Q_OBJECT" ) != -1:
                call( directory, file )
                
def doMoc( directory, filename ):
    print "parsing " + directory + "\\" + filename
    cmd = "moc.exe " + arguments + " \"" + directory + "\\" + filename + "\" -o \"" + directory + "\\moc_" + filename + "\""
#   print cmd
    os.system( cmd )

if __name__ == "__main__":
    walk( directory, doMoc )


and here is a sample arguments file:


-DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"E:\Development\QtPrecompiled-4.6\include\QtCore" -I"E:\Development\QtPrecompiled-4.6\include\QtGui" -I"E:\Development\QtPrecompiled-4.6\include\QtOpenGL" -I"E:\Development\QtPrecompiled-4.6\include" -I"E:\Development\QtPrecompiled-4.6\include\ActiveQt" -I"E:\Development\QtPrecompiled-4.6\mkspecs\win32-msvc2008" -D_MSC_VER=1500 -DWIN32