5

I just met a problem which took another couple of hours.
I've got a project which is depends on Qt. I just installed Qt 5.9.1 but errors:

E1696   cannot open source file "QDir"  Logger  \Logger.cpp 3   
E1696   cannot open source file "QFile" Logger  \Logger.cpp 4   
E1696   cannot open source file "QString"   Logger  \Logger.cpp 5   
E1696   cannot open source file "QStringBuilder"    Logger  \Logger.cpp 6   
E1696   cannot open source file "QDateTime" Logger  c\Logger.cpp    7   
E1696   cannot open source file "QMessageBox"   Logger  \Logger.cpp 8   
E1696   cannot open source file "QApplication"  Logger  \Logger.cpp 9   

still appears. Why?

I tried to add include folder to the project with $(QTDIR) variable in Properties Pages. But it refers not to the directory where I installed Qt.

kyb
  • 7,233
  • 5
  • 52
  • 105

2 Answers2

6

From QTDIR not found error building project in MSVC (this answer) I get know the problem is in *.vcxproj.user.


Solution 1.

Find all values of <QTDIR> keys in all *.vcxproj.user in solutions. For example with regexp

<QTDIR>.*</QTDIR>

and replace them with proper Qt directory, i.e.:

<QTDIR>C:\\Qt\\Qt5.9.1\\5.9.1\\msvc2017_64</QTDIR>

double \\ is for regexp. Write single \ if no regexp used.


Solution 2. Better due to its portability

Set environment variable QTDIR manually (for current user):

> setx QTDIR "C:\Qt\Qt5.9.1\5.9.1\msvc2017_64"

I think this must be done by Qt Installer. You also may like setx /m.
Next you should remove or rename all <QTDIR> keys from *.vcxproj.user files. Or delete these files at all.

DONE. Enjoy building the project. Restart MS VS could be required.


Note

The *.vcxproj.user files should not be transferred to other machines/environments, they belongs current system cinfiguration. So exclude them from your repository, i.e. with .gitignore


Possible solution 3

Use Qt Visual Studio Tools extension. I did not test this.

kyb
  • 7,233
  • 5
  • 52
  • 105
1

I ran into similiar problems, thought it was in the properties (from the property manager) at first, but turns out it was not. For me this did the trick:

-Right-click your concerning project in solution explorer and choose "Unload project". Delete the *.user file that belongs to your project.

-Reload the project again by right-clicking it in your solution explorer. Double check that the project configuration is the one you really want (Debug, 64 Bit, etc.)