Qt Creator 自动生成的垃圾(文件)的用途是什么以及如何驯服它们?

发布于 2024-09-02 23:48:46 字数 1354 浏览 14 评论 0原文

我对 Qt 相当陌生,我正在使用新的诺基亚 Qt SDK beta,并且我正在空闲时间为我的诺基亚 N900 开发一个小型应用程序。幸运的是,我能够正确设置所有内容,并在设备上运行我的应用程序。

我在学校学过C++,所以我认为这不会那么困难。我使用 Qt Creator 作为我的 IDE,因为它不能与 Visual Studio 一起使用。

我还希望将我的应用程序移植到 Symbian,因此我运行了模拟器几次,并且还针对 Windows 进行了编译以调试最邪恶的错误。 (调试器在设备上无法正常工作。)

我来自.NET背景,所以有些事情我不明白。

当我点击构建按钮时,Qt Creator 会在我的项目目录中生成一堆文件:

  • moc_*.cpp 文件 - 它们的用途是什么?
  • *.o 文件 - 我假设这些是目标代码
  • *.rss 文件 - 我不知道它们的用途,但它们绝对与RSS
  • MakefileMakefile.Debug - 我不知道
  • AppName (不带扩展名) - Maemo 的可执行文件和 AppName.sis - 我猜是 Symbian 的可执行文件?
  • AppName.loc - 我不知道
  • AppName_installer.pkgAppName_template.pkg - 我不知道
  • qrc_Resources.cpp > - 我想这是我的 Qt 资源

(其中 AppName 是相关应用程序的名称)

我注意到这些文件可以安全地删除,Qt Creator 只是重新生成它们。问题是它们污染了我的源目录。特别是因为我使用版本控制,如果它们可以重新生成,那么将它们上传到 SVN 就没有意义了。

那么,这些文件的确切用途是什么,我如何要求 Qt Creator 将它们放入另一个目录中?

编辑

Rob 推荐的似乎是最方便的解决方案,但我将 Kotti 的答案标记为已接受,因为他为我提供了有关 Qt 构建机制如何工作的最佳解释。

解决方案

到目前为止,Maemo 和 Symbian 工具链似乎都不支持影子构建,因此我在项目文件中使用这些来解决这种情况:

DESTDIR = ./NoSVN
OBJECTS_DIR = ./NoSVN
MOC_DIR = ./NoSVN
RCC_DIR = ./NoSVN
UI_HEADERS_DIR = ./NoSVN

I'm fairly new to Qt, and I'm using the new Nokia Qt SDK beta and I'm working to develop a small application for my Nokia N900 in my free time. Fortunately, I was able to set up everything correctly, and also to run my app on the device.

I've learned C++ in school, so I thought it won't be so difficult. I use Qt Creator as my IDE, because it doesn't work with Visual Studio.

I also wish to port my app to Symbian, so I have run the emulator a few times, and I also compile for Windows to debug the most evil bugs. (The debugger doesn't work correctly on the device.)

I come from a .NET background, so there are some things that I don't understand.

When I hit the build button, Qt Creator generates a bunch of files to my project directory:

  • moc_*.cpp files - what is their purpose?
  • *.o files - I assume these are the object code
  • *.rss files - I don't know their purpose, but they definitely don't have anything to do with RSS
  • Makefile and Makefile.Debug - I have no idea
  • AppName (without extension) - the executable for Maemo, and AppName.sis - the executable for Symbian, I guess?
  • AppName.loc - I have no idea
  • AppName_installer.pkg and AppName_template.pkg - I have no idea
  • qrc_Resources.cpp - I guess this is for my Qt resources

(where AppName is the name of the application in question)

I noticed that these files can be safely deleted, Qt Creator simply regenerates them. The problem is that they pollute my source directory. Especially because I use version control, and if they can be regenerated, there is no point in uploading them to SVN.

So, what the exact purpose of these files is, and how can I ask Qt Creator to place them into another directory?

Edit

What Rob recommended seems to be the most convenient solution, but I marked Kotti's answer accepted, because he provided me with the best explanation about how Qt's build mechanism works.

The solution

It seems that neither the Maemo nor the Symbian toolchain supports shadow builds as of yet, so I use these in my project file to solve the situation:

DESTDIR = ./NoSVN
OBJECTS_DIR = ./NoSVN
MOC_DIR = ./NoSVN
RCC_DIR = ./NoSVN
UI_HEADERS_DIR = ./NoSVN

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

白云悠悠 2024-09-09 23:48:46

不是您问题的完整答案,而只是问题的一部分:)此外,它可以在谷歌上搜索。

猜猜如果你用C++开发,你应该知道Makefile代表什么。另外,我认为 .loc 文件通常是一个包含本地化字符串/内容的文件。

替代文本
(来源:thelins.se

将 C++ 构建系统与 Qt 构建系统进行比较,您可以看到 C++ 构建系统(灰色框)未进行修改。我们仍然在这里构建 C++ 代码。但是,我们添加了更多源和标头。这里涉及到三个代码生成器:

元对象编译器(图中的 moc) – 元对象编译器获取以 Q_OBJECT 宏开头的所有类并生成 moc_*.cpp C++ 源文件。该文件包含有关被 moc 的类的信息,例如类名、继承树等,还包含信号的实现。这意味着当您发出信号时,您实际上调用了 moc 生成的函数。

用户界面编译器(图中的 uic) – 用户界面编译器从 Designer 获取设计并创建头文件。然后,这些头文件会像往常一样包含到源文件中,从而可以调用 setupUi 来实例化用户界面设计。

Qt 资源编译器(图中为 rcc) – 资源编译器是我们尚未讨论的内容。它可以将图像、文本文件等嵌入到可执行文件中,但仍然可以将它们作为文件进行访问。我们稍后会看到这个,我只是想将它包含在它所属的图片中。

我希望这个插图能够阐明 Qt 到底做了什么来向 C++ 添加新的好关键字。如果您好奇 - 请随意阅读一些生成的文件。只是不要更改它们 - 每次构建应用程序时它们都会重新生成。

如果您使用 QtCreator,则会在项目目录的 debug 和release 子目录中生成 moc 文件。 uic 文件存储在项目目录的根目录中。 rcc 文件通常很无聊,但我确信您可以在项目目录层次结构中的某个位置找到它们。


编辑:您不必将这些文件包含到 SVN 中。这与提交 .ncb.pdb 和其他临时文件几乎是一样的。每次您在 Qt 应用程序中更改某些内容时,这些临时文件都会重新生成作为更改的更新,因此将它们提交到 SVN 是没有意义的。

Not a fully answer to your question, but just part of it :) Also, it's googlable.

Guess that if you develop in C++, you should know what does Makefile stand for. Also I think the .loc file is generally a file with localized strings / content.

alt text
(source: thelins.se)

Comparing the C++ build system to the Qt build system, you can see that the C++ build system, (the gray boxes), are left unmodified. We are still building C++ code here. However, we add more sources and headers. There are three code generators involved here:

The meta-object compiler (moc in the illustration) – the meta-object compiler takes all classes starting with the Q_OBJECT macro and generates a moc_*.cpp C++ source file. This file contains information about the class being moc’ed such as class name, inheritance tree, etc, but also implementation of the signals. This means that when you emit a signal, you actually call a function generated by the moc.

The user interface compiler (uic in the illustration) – The user interface compiler takes designs from Designer and creates header files. These header files are then included into source files as usual, making it possible to call setupUi to instanciate a user interface design.

The Qt resource compiler (rcc in the illustration) – The resource compiler is something we have not talked about yet. It makes it possible to embedd images, text files, etc into your executable, but still to access them as files. We will look at this later, I just want to include it in this picture where it belongs.

I hope this illustration clarifies what Qt really does to add new nice keywords to C++. If you are curious – feel free to read some of the generated files. Just don’t alter them – they are regenerated each time you build your application.

If you are using QtCreator, the moc files are generated in the debug and release sub-directories of your project directory. The uic files are stored in the root of the project directory. The rcc files are generally boring, but I’m sure that you can find them in your project directory hierarcy somewhere.


Edit: You don't have to include these files into your SVN. This is pretty the same crap as commiting .ncb, .pdb and other temporary files. Every time you change something in your Qt application, these temporary files get regenerated as an update to your changes, so there is no sense to commit them to SVN.

初见终念 2024-09-09 23:48:46

您可以告诉 qmake(以及 QtCreator)将生成的文件放在其他地方,方法是将以下内容添加到项目的 .pro 文件中。

UI_DIR = .ui
MOC_DIR = .moc
OBJECTS_DIR = .obj

这会将所有 ui 文件放在 .ui 目录中,将 moc 文件放在 .moc 目录中,并将所有 .o 文件放在其中。 .obj 目录中的文件。 (当然你可以根据需要更改这些)

qmake的相关帮助位于:
http://doc.qt.io/archives/ 4.6/qmake-variable-reference.html#moc-dir

You can tell qmake (and therefore QtCreator) to put the generated files elsewhere by adding the following to your .pro file for the project

UI_DIR = .ui
MOC_DIR = .moc
OBJECTS_DIR = .obj

This would put all ui files in the .ui directory, moc files in the .moc director and all .o files in the .obj directory. (Of course you can change these as you like)

The relevant help for qmake is at:
http://doc.qt.io/archives/4.6/qmake-variable-reference.html#moc-dir

囍孤女 2024-09-09 23:48:46

如果您使用影子构建(在 Qt Creator 2.0 beta 中默认启用)然后所有这些临时文件都会在单独的文件夹中创建。例如:

\MyProjects\ProjectFoo
\MyProjects\ProjectFoo-build

恕我直言,非常有用。

If you use shadow builds (enabled by default in the Qt Creator 2.0 beta) then all of these temporary files are created in a separate folder. For example:

\MyProjects\ProjectFoo
\MyProjects\ProjectFoo-build

Very useful IMHO.

才能让你更想念 2024-09-09 23:48:46

不要尝试获取存储在另一个目录中的文件;相反,告诉 subversion 忽略它们,如 http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.ignore.html

大多数源代码控制系统都对忽略生成的文件有很好的支持,因为这是几乎每个软件项目都会遇到的问题。

Don't try to get the files stored in another directory; rather, tell subversion to ignore them, as explained at http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.ignore.html , for example.

Most source control systems have good support for ignoring generated files, since this is a problem hit by almost every single software project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文