Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Qt recognize my header file? cannot open include file No such file or directory

Tags:

c++

qt

I have the below in my .pro file and I have files that #include "headerhere". For example: #include "StdAfx.h". However I'm getting an

error Cannot open include file: 'StdAfx.h': No such file or directory.

I get the same error whether I use #include "StdAfx.h" or #include "Shared/StdAfx.h". This is extremely frustrating and I can't do any actual work unless Qt starts recognizing my headers. I've found online no solution for this. What is going on?

.pro file has:

HEADERS  += ibproject.h \
Shared/StdAfx.h \
Shared/TwsSocketClientErrors.h \
Shared/TagValue.h \
Shared/shared_ptr.h \
Shared/ScannerSubscription.h \
Shared/OrderState.h \
Shared/Order.h \
Shared/IBString.h \
Shared/HScrollListBox.h \
Shared/Execution.h \
Shared/EWrapper.h \
Shared/EClientSocketBaseImpl.h \
Shared/EClientSocketBase.h \
Shared/EClient.h \
Shared/Contract.h \
Shared/CommonDefs.h \
Shared/CommissionReport.h \
SocketClient/src/EClientSocket.h
ewrappersubclass.h 

INCLUDEPATH += $$PWD/SocketClient
DEPENDPATH += $$PWD/SocketClient

EDIT: why I am getting downvotes? This is a legitimate problem I'm having

Image showing it recognizes and doesn't recognize simultaneously

like image 623
Terence Chow Avatar asked Apr 27 '13 22:04

Terence Chow


People also ask

What happens if header file is not included?

Even if it does not, it will certainly waste time. This construct is commonly known as a wrapper #ifndef. When the header is included again, the conditional will be false, because FILE_FOO_SEEN is defined. The preprocessor will skip over the entire contents of the file, and the compiler will not see it twice.

Can you include header files in header files?

Yes, this will work. Note, however, that if you include a lot of headers in this file and don't need all of them in each of your source files, it will likely increase your compilation time.

How do I include a header file?

You make the declarations in a header file, then use the #include directive in every . cpp file or other header file that requires that declaration. The #include directive inserts a copy of the header file directly into the . cpp file prior to compilation.

Where is .pro file Qt Creator?

Double-click the . pro file in the Finder/File Explorer. In the Qt Creator application, choose menu File->Open File or Project, navigate to the project folder and choose the . pro file to open.


2 Answers

I had the same problem as well. The reason was that I use two computers in parallel and the makefile tried to find files at paths as they are set on the previous one. But everything seemed to be fine - as in your case, tooltip when hovering over the include showed me the correct path, also F2 (follow symbol under cursor) navigated me to the correct header.

I thought qmake is re-maked each time I change something in the .pro file, but obviously not.

Just run Build->qmake, it should fix it.

like image 131
vitakot Avatar answered Sep 22 '22 06:09

vitakot


You need to update the qmake file.

Build-> Run qmake
like image 32
Sirga Avatar answered Sep 22 '22 06:09

Sirga