Visual Studio 2008 中的 Qt4

编程入门 行业动态 更新时间:2024-10-21 12:40:10
本文介绍了Visual Studio 2008 中的 Qt4 - moc-ed 文件被排除在构建之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

最近我从 Qt Software 安装了 VS Addin,并将我的 .pro 项目导入到 VS2008.一般来说,一切正常,只有一个小而烦人的例外.

Recently I have installed VS Addin from Qt Software and I imported my .pro project to VS2008. Generally, all works fine, with one small but annoying exception.

假设我有一个 file.cpp,其中有一个声明它是 Q_OBJECT 的类.因此,文件是 MOC-ed 并生成 moc_file.cpp,并且在生成的文件"下的解决方案中可用.到目前为止一切顺利.

Suppose I have a file.cpp with has a class which declares that it is a Q_OBJECT. So, as such the file is MOC-ed and moc_file.cpp is generated, and is available in Solution under "Generated files". So far so good.

有趣的是,当我更改 file.cpp 中的某些内容(例如添加一行),并使用 Ctrl+S 保存文件时,moc_file.cpp 会被排除在构建之外(您可以看到一个无输入符号在图标上).当我按 F7 构建解决方案时,我遇到了很多典型的链接器错误.为了解决这种情况,我需要转到 moc_file.cpp 的属性并将从构建中排除"从是"更改为否".然后一切正常.

The funny thing is, when I change something in file.cpp (add a line, for example), and save the file using Ctrl+S, the moc_file.cpp becomes excluded from build (you can see a no entry sign on the icon). And I hit lots of typical linker errors when I press F7 to build a solution. In order to fix the situation, I need to go to the properties of moc_file.cpp and change "Exclude from build" from "Yes" to "No". Then everything works fine.

其他人有同样的经历吗?我做错了什么吗?

Is someone else experiencing the same? Am I doing something wrong?

推荐答案

问题已解决.我发现在描述我的项目的手工制作的 .pro 文件中,我将 MOC_DIR 指定为:

Problem solved. I found out that in my hand-crafted .pro file describing my project, I had MOC_DIR specified as:

MOC_DIR = .moc

MOC_DIR = .moc

导入到 Visual Studio 目录后,生成的文件"对于发布和调试都是相同的.因此,例如,当我的活动配置是 Debug 时,当我保存一个文件时,它会被排除在构建之外,因为它对于与 Release 相关的文件是明智的——正如 rpg 和 Andrew 建议的那样.将目录更改为 .moc\$(ConfigurationName) 后,问题不再出现(我在解决方案中看到每个生成的文件有 2 个版本 - 每个配置一个).

After importing to Visual Studio directory for "Generated files" was the same for both Release and Debug. So, when my active configuration was Debug for example, when I saved a file it became excluded from build because it was sensible for Release-related file - just as rpg and Andrew suggested. After changing the directory to .moc\$(ConfigurationName) the problem is no longer seen (and I see 2 versions of each generated file in my solution - one for each configuration).

感谢大家的帮助!

这篇关于Visual Studio 2008 中的 Qt4 - moc-ed 文件被排除在构建之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 12:20:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154887.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Studio   Visual

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!