I'm trying to link Qt5 in Visual Studio 15 2017.
I have added the paths and file references for additional (1) include directories, (2) library directories and (3) dependencies in the Property Pages.
I can include header files by refering to their path like this
#include <QtWidgets/qpushbutton.h>
However, the github project I'm trying to build uses this line
#include <QtWidgets>
Visual Studio shows me an error on those lines
E1696 cannot open source file "QtWidgets"
When creating a solution from a .pro
file using the Qt VS Tools in Visual Studio, I can include <QtWidgets>
. But how can I include it in my existing project, which has not been created from a .pro
file.
Solution
Placing a MyProjectName.pro file (with QT += core gui widgets
) in the MyProjectName Folder and opening it with Qt VS Tools > Open Qt Project File (.pro) solves this problem. I can now include <QtWidgets>
. But this doesn't seem like the correct way, given the VS gui.
The "QtWidgets" include file is a file in the "QtWidgets" directory. Your include path probably has something like "$(QTDIR)/include", but not "$(QTDIR)/include/QtWidgets". That's why your example with "QtWidgets/qpushbutton.h" works, but not just "QtWidgets" on its own.
Maybe it helps to look at the full path to the file you're trying to include (using my Qt 5.5.1 installation):
C:\Qt\Qt5.5.1\5.5\msvc2013_64\include\QtWidgets\QtWidgets
So if you have this in your include path:
C:\Qt\Qt5.5.1\5.5\msvc2013_64\include
That only gets you to the QtWidgets directory, but not to the QtWidgets file.
You also needs this in your include path:
C:\Qt\Qt5.5.1\5.5\msvc2013_64\include\QtWidgets
Obviously, adjust this for your installed drive, Qt version, and MSVC version.