Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Creator can't find headers (says: "No such file or directory")

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?

When I open a C file in Qt Creator and say

#include <stdio.h>

it underlines the line and says

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?

Update

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?

like image 209
user541686 Avatar asked Mar 05 '12 19:03

user541686


People also ask

Where are Qt header files?

The Qt header files are packaged as a zip file in the devkitBase\include directory on Windows, and as a tarred and zipped file in devkitBase/include on macOS and Linux.

Does Qt need Creator?

You certainly don't have to use QtCreator to write a Qt program. You also don't have to use qmake but you are asking for trouble by not using it. To do anything even remotely interesting in Qt you will inevitably end up subclassing QObject .


2 Answers

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

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.

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.

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

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!

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.

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.

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

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).

like image 123
Gui13 Avatar answered Oct 09 '22 13:10

Gui13


which operating system and compiler you are using and version of both? Check if the environment variables of the install is correct, for example Where is the headers of c++?. A variation is to add the path of the "includes of your headers" to the project configuration in the left panel go to "project - program - target" and add the path of the includes. another is to add the full path to the location of the c++ standard headers to the variable "includepath" in your .pro file.

like image 37
jordenysp Avatar answered Oct 09 '22 14:10

jordenysp