Error: "QtGui / QMainWindow": there is no such file or directory: Qt 5.1.1

I installed Qt5.1.1 and am creating a new Gui application. The code in mainwindow.h shows:

 #if QT_VERSION >= 0x050000 #include <QtWidgets/QMainWindow> #else #include <QtGui/QMainWindow> #endif 

I think everything is in order. But when I run it, I have the following:

 error: C1083: Cannot open include file: 'QtGui/QMainWindow': No such file or directory 

I know when I replace

 #if QT_VERSION >= 0x050000 #include <QtWidgets/QMainWindow> #else #include <QtGui/QMainWindow> #endif 

to

 #include <QtWidgets/QMainWindow> 

it works.

I'm just wondering why the default code is wrong and how to make the destructive code correct.

+7
windows
source share
2 answers

You may have another option.

You can also add widgets to your .pro file, for example

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

By adding this line to the .pro file, now you just don’t have to worry about the Qt version and include a file like <QtGui/QMainWindow> or <QtWidgets/QMainWindow>

Hope this will be helpful for you.

+13
source share

I had the same problem, but this is with the nuances. If this code is in the .h file:

  #if QT_VERSION >= 0x050000 #include <QtWidgets/QMainWindow> #else #include <QtGui/QMainWindow> #endif 

an error. It seems that QT_VERSION is not defined correctly. But if I translate this code into a .cpp file, everything is fine. The problem was solved as follows:
1. Add to the .pro file:

  greaterThan(QT_MAJOR_VERSION, 4) { QT += widgets DEFINES += HAVE_QT5 } 

2. Add to the .h file:

  #ifdef HAVE_QT5 #include <QtWidgets/QMainWindow> #else #include <QtGui/QMainWindow> #endif 
+2
source share

All Articles