头文件含有Q_OBJECT macro的编译(转载)

Signals and slots is quite easy, check one of the examples and you'll immedeately get away with it.
If you don't have the QMsnet plugin it's a bit of a pain to setup the moc step though, you have to manually add something like this in the .vcproj file (or write a macro that adds a custom build step), for every header that contains a Q_OBJECT macro:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<File RelativePath=".\app\mainapp.h">
	<FileConfiguration
		Name="Debug|Win32"
	>
	<Tool
		Name="VCCustomBuildTool"
		Description="Moc&apos;ing mainapp.h..."
		CommandLine="$(QTDIR)\bin\moc.exe .\app\mainapp.h -o tmp\moc\moc_mainapp.cpp"
		AdditionalDependencies="$(QTDIR)\bin\moc.exe"
		Outputs="tmp\moc\moc_mainapp.cpp"
	/>
	</FileConfiguration>
	<FileConfiguration
		Name="Release|Win32"
	>
	<Tool
		Name="VCCustomBuildTool"
		Description="Moc&apos;ing mainapp.h..."
		CommandLine="$(QTDIR)\bin\moc.exe .\app\mainapp.h -o tmp\moc\moc_mainapp.cpp"
		AdditionalDependencies="$(QTDIR)\bin\moc.exe"
		Outputs="tmp\moc\moc_mainapp.cpp"
	/>
	</FileConfiguration>
</File>


and also add the tmp\moc\moc_mainapp.cpp to your project

same goes for *.ui files except they need uic.exe instead of moc.exe

posted on 2010-05-20 14:50  CGDeveloper  阅读(1028)  评论(0编辑  收藏  举报

导航