Qt Creator无法找到标题(例如:“没有这样的文件或目录") [英] Qt Creator can't find headers (says: "No such file or directory")

查看:87
本文介绍了Qt Creator无法找到标题(例如:“没有这样的文件或目录")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何告诉Qt Creator 2.4.1(基于Qt 4.7.4 32位)在默认情况下查找头文件的位置?

How can I tell Qt Creator 2.4.1 (based on Qt 4.7.4 32-bit) where to look by default for header files?

当我在Qt Creator中打开一个C文件并说

When I open a C file in Qt Creator and say

#include <stdio.h>

下划线并说

stdio.h: No such file or directory

我想告诉它在我选择的目录中查找标题;我该怎么做?

I would like to tell it to look for headers in a directory of my choice; how do I do this?

我想我也应该问:这甚至可能吗?还是每次我想编辑一个独立的C ++文件时都必须创建一个整个项目?

I guess I should also ask: Is this even possible? Or must I create an entire project every time I want to edit a standalone C++ file?

推荐答案

我发现自己经常遇到这个问题.我现在也可以在我的机器上进行复制(Mac OS).

I found myself often faced with this problem. I can reproduce it on my machine right now as well (Mac OS).

QtCreator似乎需要一个项目来正确处理GCC路径分析(在Qt框架路径之上).
Qt用于查找标头的过程是,它启动带有特殊参数的GCC(或Windows上的编译器),使它们输出编译器查找标头的路径.要这样做,它必须有一个与您的文件相关联的项目,因为它使用该项目来确定要使用的工具链,从而找到GCC.

It looks like QtCreator needs to have a project to correctly handle GCC path analysis (on top of Qt frameworks paths).
The process Qt uses to find the headers is that it launches GCC (or your compiler on Windows) with special arguments that make it output the paths where the compiler finds its headers. BUT, to do that, it must have a project associated to your files, because it uses this project to determine what toolchain to use, thus where GCC is found.

答案是这样的:始终创建一个项目,以使用语法分析.
请注意,在创建此项目时,定义要使用的Qt SDK版本和工具链是非常重要的,否则语法control-click无效.

So the answer is this: create a project, always, to use the syntax analyzis.
Note that it is quite important that when you create this project, you define which version of the Qt SDK and the toolchain you'll use, otherwise the syntax control-click won't work.

您可能会发现一些使用Qt Project文件的有趣方法,尽管没有使用Qt SDK或使用Creator创建项目.在此处查看类似问题的答案: https://stackoverflow.com/a/5817226/389405

You might find some interesting ways of using a Qt Project file although not using the Qt SDK or using Creator to build your project. See an answer to a similar question here: https://stackoverflow.com/a/5817226/389405

请注意,我个人使用此方法,其 .pro 文件仅列出了我项目的所有子目录,并禁用了所有键盘快捷键,因此我仅将Qt Creator用作编辑.语法高亮/链接很棒,而且比Eclipse快得多,快得多!

Note that I personnally use this method, with a .pro file that simply lists all the subdirectories of my project, and with all keyboard shortcuts to build disabled, so that I only use Qt Creator as an editor. The syntax highlighting/linking is awesome and exceptionnally quick, far, far quicker than Eclipse!

为此,只需在项目目录中发出 qmake -pro .它将创建一个 [DIR] .pro 文件,您可以随时将其删除.

To do that, simply issue qmake -pro in the directory of your project. It will create a [DIR].pro file that you can remove any time.

一年前,我在此语法分析的一个方面填补了一个错误,该问题困扰着我: https://bugreports.qt.io/browse/QTCREATORBUG-4846 ,原因是我使用的编译器以法语而不是英语输出数据.他们修复了2.4版中的代码,但是它可能是特定于Unix的(有关更多信息,请参见问题的注释),因此您可能需要测试是否可以将此问题应用于您的案例.

I filled a bug a year ago on an aspect of this syntax analyzis that was bothering me here: https://bugreports.qt.io/browse/QTCREATORBUG-4846, the reason beiing that the compiler I use output its data in French instead of English. They fixed the code in 2.4 but it might be Unix-specific (see the comments of the issue for more information) so you'll probably want to test if this issue can be applied to your case.

如果即使为您的版本创建了项目后问题仍然存在,请确保将其指向qt-project.org上的人员!

If your issue continues even after creating a project for your edition, make sure to point it to the guys at qt-project.org !

否则,我看到的唯一解决方案是修改QtCreator的源代码.您可以在他们的最后一篇文章中找到有关如何捐款的一些信息: https://blog.qt.io/blog/2012/03/15/qt-creator-2-5-beta/(并尝试使用支持C ++ 的新Beta版lambdas ).

Otherwise, the only solution I see is modifying the source code of QtCreator. You can find in their last post some information about how to contribute here: https://blog.qt.io/blog/2012/03/15/qt-creator-2-5-beta/ (and try their new beta which supports C++ lambdas).

这篇关于Qt Creator无法找到标题(例如:“没有这样的文件或目录")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆