---
title: "解决用QtCreator编译examples时出现的错误"
author: "adrift"
date: "2011-10-08T11:45:35Z"
tags: []
categories: ["开源软件"]
slug: "qtcreator-examples"
draft: false
lastmod: "2011-10-08T11:45:35Z"
id: 1186695
url: "https://adrift.iteye.com/blog/1186695"
---

下载最新(2010.04)版本的Qt之后，运行QtCreator，打开其examples工程，编译，出现"main.moc: No such file or directory"错误。

在网上找了一下，发现下面这个讨论

[http://bugreports.qt.nokia.com/browse/QTCREATORBUG-1889?focusedCommentId=121848&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel](http://bugreports.qt.nokia.com/browse/QTCREATORBUG-1889?focusedCommentId=121848&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel)

 

原来是因为Qt发行打包的时候不小心将一些临时生成的文件也打进来了。

这些临时生成的文件(各种moc等)和实际编译环境可能不符合，但是qmake发现其存在所以也就不自动重新生成了，结果在链接时发现不正确。

 

解决办法就是删除examples目录下的所有"tmp"子目录，然后Clean Projects然后run qmake然后Build Projects就可以了。

 

编译examples/tools/plugandpaint时又发现一个错误，在下面的讨论

[http://forum.mandriva.com/viewtopic.php?t=91735](http://forum.mandriva.com/viewtopic.php?t=91735)

的提示下发现examples/tools/plugandpaint.pro写的有点小问题，需要做如下修改:

1)将

LIBS = -L$${QT\_BUILD\_TREE}/examples/tools/plugandpaint/plugins -lpnp\_basictools

修改成

LIBS = -L$${QT\_BUILD\_TREE}/examples/tools/plugandpaint/plugins -Lplugins -lpnp\_basictools

 

2)将

mac:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)\_debug

win32:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)d

修改成

mac:LIBS = $$member(LIBS, 0) $$member(LIBS, 1) $$member(LIBS, 2)\_debug

win32:LIBS = $$member(LIBS, 0) $$member(LIBS, 1) $$member(LIBS, 2)d

后就可以了。