Cannot open include file: 'QtWidgets/qtwidgetsglobal.h' on vs2017 - c++

[Solved]
Additional include directories should be:
C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include,
not C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include\QtWidgets
as the statement in qapplication.h is "#include <QtWidgets/qtwidgetsglobal.h>"
When I was running this on VS2017(x86) on win10, I got the error below:
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
return 0;
}
fatal error C1083: Cannot open include file: 'QtWidgets/qtwidgetsglobal.h'
The qtwidgetsglobal.h file is just in the directory, but I don't know why VS can't open it.
It seems that compiler can open QApplication(is it the same as qapplication.h?), but can't open the first #include file 'qtwidgetsglobal.h' in QApplication... Why?
I have set the additional include and lib directories in project settings
Additional include directories :
C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include\QtWidgets
Additional lib directories:
C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\lib
I have also installed Qt VS Tools and added the qt version
qt vs tools options
I have also tried the 'winrt_x86_msvc2017'directory, and it came to the same error. I can't find 'msvc2017' directory, there's only 'msvc2017_64'.
Any ideas would be appreciated

Additional include directories should be:
C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include,
not C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include\QtWidgets
as the statement in qapplication.h is #include <QtWidgets/qtwidgetsglobal.h>

Related

Problems to include QT Liraries

I'm currently learning Qt and I'm having some problems to include libraries to my visual studio project. I have installed the Qt5 libraries with vcpkg and used the command vcpkg integrate install correctly.
In my project I have the following code:
#include <iostream>
#include <QApplication>
using namespace std;
int main(int argc, char* argv[]) {
cout << "hello";
}
Very simple. besides that I have the following configuration in vcpkg properties
Properties vcpkg
And i`m having the following two errors:
Cannot open source file "QApplication"
Cannot open include file qt5/QtWidgets/QApplication: no such file or directory
How can I include the librarie?

How to compile a Qt program without qtCreator on Windows?

I have read the question Can I use Qt without qmake or Qt Creator? which is basically the same for Linux, and very useful.
How to compile a basic program using QtCore (console application, even without GUI) on Windows, without using qmake or qtCreator IDE, but just the Microsoft VC++ compiler cl.exe?
For example, let's say we have:
#include <iostream>
#include <QtCore>
int main()
{
QVector<int> a; // Qt object
for (int i=0; i<10; i++)
a.append(i);
std::cout << "hello";
return 0;
}
Using:
call "C:\path\to\vcvarsall.bat" x64
cl main.cpp /I D:\coding\qt\qtbase-everywhere-src-5.15.5\include
fails with:
D:\coding\qt\qtbase-everywhere-src-5.15.5\include\QtCore\QtCore(3): fatal error C1083: Cannot open include file: 'QtCore/QtCoreDepends': No such file or directory
Indeed this file is not present in the release qtbase-everywhere-opensource-src-5.15.5.zip from https://download.qt.io/archive/qt/5.15/5.15.4/submodules/.
TL;DR: More generally, which cl.exe arguments should we use to to able to use all Qt includes, and effectively compile such a minimal project using QtCore?
I finally managed to do it 100% from command line, without the qtCreator IDE, but not yet without qmake. Steps to reproduce:
Let's assume Microsoft MSVC 2019 is installed.
Install qt-opensource-windows-x86-5.14.2.exe. (This is the latest Windows offline installer I could find), double check that you install at least msvc2017_64.
Note: Don't use qtbase-everywhere-opensource-src-5.15.4.zip: using the include subfolder from this package for cl.exe /I ... is not enough. (I thought it would, at first)
Create a folder example containing the main.cpp file above
Open a command line window in this folder and do:
vcvarsall.bat x64
Now either do "c:\path\to\msvc2017_64\bin\qmake.exe" -project to create a example.pro project file or create it manually with:
TEMPLATE = app
TARGET = qt_example
INCLUDEPATH += .
CONFIG += console
SOURCES += main.cpp
Do "c:\path\to\msvc2017_64\bin\qmake.exe". This will create a Makefile file.
Run nmake. This is Microsoft MSVC's equivalent of the make tool.
Copy c:\path\to\msvc2017_64\bin\Qt5Core.dll into the release folder
Run release\example.exe. Working!
Addendum: here is solution now for a minimal GUI app:
main.cpp
#include <QtCore/QCoreApplication>
#include <QTextStream>
#include <QMessageBox>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMessageBox::information(NULL, "Hello", "Hello", "Ok");
return a.exec();
}
qt_example_gui.pro
TEMPLATE = app
TARGET = qt_example_gui
INCLUDEPATH += .
SOURCES += main.cpp
QT += gui widgets
Do the vcvarsall.bat x64, qmake, nmake like in the solution above. No be sure you have this file structure:
release\qt_example_gui.exe
release\Qt5Core.dll
release\Qt5Gui.dll
release\Qt5Widgets.dll
release\platforms\qwindows.dll
Run the .exe, that's it!

Struggle with QGIS C++ API

I'm trying to create a simple application using QGIS SDK. But currently, I'm stuck with API at very beginning stage.
belows are the env.
Windows 7
MSVC 2015
QGIS SDK (downlaod by OSGeo4w) include:
qgis-dev(3.2.3)
Qt5(5.9)
here is the OSGeo4w directory
here is the OSGeo4w/app directory
And start by create an empty project, property settings:
C/C++ -> General -> Additional Include Directories
C:\OSGeo4W\apps\Qt5\include
C:\OSGeo4W\apps\Qt5\include\QtCore
C:\OSGeo4W\apps\Qt5\include\QtGui
C:\OSGeo4W\apps\Qt5\include\QtWidgets
C:\OSGeo4W\apps\Qt5\include\QtXml
C:\OSGeo4W\apps\qgis-dev\include
C:\OSGeo4W\include
Linker -> General -> Additional Library Directories
C:\OSGeo4W\apps\Qt5\lib
C:\OSGeo4W\apps\qgis-dev\lib
Linker -> Input -> Additional Dependencies
qtmaind.lib
Qt5Cored.lib
Qt5Guid.lib
Qt5Widgetsd.lib
qgis_core.lib
qgis_app.lib
qgis_gui.lib
The test code is quite simple:
main.cpp
#include <QtWidgets/QApplication>
#include <qgsapplication.h>
int main(int argc, char *argv[])
{
QgsApplication a(argc, argv, true);
// QgsApplication::setPrefixPath("C:/path/to/OSGeo4W64/apps/qgis", true);
// QgsApplication::initQgis();
// ImageViewer w;
// w.show();
return a.exec();
}
however, errors occured when I build it,
(1)no instance of constructor "QgsMapUnitScale::QgsMapUnitScale" matches the argument list (qgsrendercontext.h)
(2)"M_PI": undeclared identifier (qgsabstractgeometry.h)
here is the build error messages
Could anyone give me a suggestion?I have some difficulties to understand how the API should work and there is really few doc. and resource about
QGIS C++ developement on internet, even on QGIS offical website.
I appreciate any help, thanks.

file found from one .cpp file, but give "No such file or directory" from another .cpp file

in CCellBridge.cpp, CCellBridge.h is found
but in main.cpp, CCellBridge.h gives:
main.cpp:15:25: fatal error: CCellBridge.h: No such file or directory
#include "CCellBridge.h"
i even copy/paste
#include "CCellBridge.h"
from CCellBridge.cpp into main.cpp
in main.cpp, it will see the functions from CCellBridge.h
i have cleaned/compiled, closed, clean/compiled, but the error still shows.
how can the IDE see the class, but the compiler can not?
both files are in same project.
i have closed file and opened file in project just to make sure it was the correct file.
this is in main, it sees it. no yellow or red lines under code.
CCellBridge cellBridge = new CCellBridge();
cellBridge.GetFire();
type
cellBridge.
and list of functions show up
yet
#include "CCellBridge.h"
in main.cpp has yellow line under it
guess this needs clarifying:
file CCellBridge.cpp
//
#include "CCellBridge.h"
CCellBridge::CCellBridge()
{
}
works
file main.cpp
#include <cstdlib>
#include "CCellBridge.h"
using namespace std;
int main(int argc, char** argv)
{
CCellBridge cellBridge = new CCellBridge();
return 0;
}
does not work
file main.cpp
#include <cstdlib>
#include "CCellBridge.h"
using namespace std;
int main(int argc, char** argv)
{
CCellBridge cellBridge = new CCellBridge();
cellBridge. [note: this give list of function in class CCellBridge]
return 0;
}
Did you add the include directories path properly in the Project Settings in your IDE(assuming its Visual Studio).
Open C/C++ General tab in VS IDE and check against the first entry "Additional Include Directories". The directory containing "CCellBridge.h" should be present in this list.
Let me know if this helps!!
i verified that it was NOT in same folder. had to remove files from project, copy files to project folder, add files to project.

Using Qt to configure OpenCV library failed

I'm new to Qt creator. Yesterday, I followed the official instructions to configure OpenCV library but it failed. I tried everything on the Internet but it just didn't work. Detailed are listed as belows:
test code is simple, I only want to ensure whether the library works:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Hello World!" << endl;
return 0;
}
My project configuration is like below :
I thought there might be a problem in debugger. I configure the debugger and I'm quite sure it's ok. The picture is here:
But it just doesn't work. When I click build and run, it says:
C1083: cannot open containing files: "opencv2/opencv.hpp": No such
file or directory.
What's strange is when I include <files> in the editor, the automatic code completion can detect the existence of the OpenCV library and hint after <opencv2/> that there are opencv.hpp, core.hpp .etc. and in the Include Hierarchy, the opencv.hpp exists.
So what might be the problem?