16

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

O'Neil
  • 3,790
  • 4
  • 16
  • 30
Terence Chow
  • 10,755
  • 24
  • 78
  • 141
  • So which directory has "stdafx.h"? – john Apr 27 '13 at 22:35
  • @john it's currently in `shared/stdafx.h` but to be honest I've copied it and pasted in both the root and the shared folder just to test if it was because I had some syntax wrong. Nope, it doesn't recognize it even when its in both folders – Terence Chow Apr 27 '13 at 22:37
  • 3
    I don't know QT but have you tried adding the directory with stdafx.h to INCLUDEPATH, something like `INCLUDEPATH += $$PWD` – john Apr 27 '13 at 22:40
  • @john I've tried including both `$$PWD` and `$$PWD/Shared` but it didn't help – Terence Chow Apr 27 '13 at 22:54
  • 1
    this is a perfectly valid question; I'm having the exact same issue. did you find a solution? – johnbakers Sep 18 '13 at 06:20
  • @OpenLearner unfortunately not. After a few hiccups restarting it worked..then it didn't work again...It was so frustrating I just redid the project in a different GUI... – Terence Chow Sep 25 '13 at 22:52
  • Little bit offtop, but - stdafx.h is a pure MS Visual Studio feature, I think that you shouldn't use it in Qt Creator. – QtRoS Jan 29 '15 at 09:14

7 Answers7

13

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.

vitakot
  • 3,786
  • 4
  • 27
  • 59
9

You need to update the qmake file.

Build-> Run qmake
Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121
Sirga
  • 91
  • 1
  • 2
3

add in .pro INCLUDEPATH += $$_PRO_FILE_PWD_

stephone
  • 167
  • 2
  • 9
  • This solved my problem. The project was working well weeks but when I changed compilation kit, one header file was not found anymore. Adding this INCLUDEPATH to *.pro file solved the problem but I do not still understand what happened and why the change had to be done? – Petri Pyöriä Oct 21 '15 at 09:04
1

I have this issue from time to time, mostly when I make a pull request or copy code around.

The easy solution is to delete all qt generated files, and Build->qmake then Rebuild all.

This is a Qt Bug that it does not properly identify files that need to be regenerated and, even though the IDE links everything nicely, that error happens at compile time. The same happens when it generates ui_formname.h header files, some changes are not made effective straight away.

Sometimes, restarting the QtCreator is necessary. Doing the deleting and restarting always solves this exact issue.

Have a nice day!

0

The file is not in your include path.

The HEADERS part of a pro file lists header files that the project depends on. These files are considered for processing by moc if they have the Q_OBJECT macro in the class definition. Adding a file to HEADERS does not put it in the include search path.

You also have a stray header (ewrappersubclass.h) because you forgot to escape the end of line.

I suspect that the reason for this is a Windows case sensitivity problem. The compiler is case sensitive but the file system is not; or vice-versa. Such that you #include "shared/stdafx.h" when you should #include "Shared/StdAfx.h".

koan
  • 3,596
  • 2
  • 25
  • 35
  • I've added a screenshot so you can see that I did in fact type the case correctly. My `INCLUDESPATH` does not need to add the `StdAfx.h` because I am including it with `Shared/StdAfx.h`...Any idea why this is happening? – Terence Chow Apr 27 '13 at 23:27
  • You should look at the Makefile generated with qmake to find out what include path is given to the compiler – koan Apr 29 '13 at 12:43
0

It is most likely because of the previous C1189 error, see here.

cmannett85
  • 21,725
  • 8
  • 76
  • 119
0

I know this post is very old but It just happened to me.

INCLUDEPATH += $$PWD

did the trick. Don't forget to do qmake and then build all.

All the best!

O'Neil
  • 3,790
  • 4
  • 16
  • 30
kentropy
  • 103
  • 4