Error : 'QtGui/QMainWindow': No such file or directory : Qt 5.1.1
Asked Answered
A

2

7

I have installed the Qt5.1.1 and create a new Gui Application. The code in mainwindow.h shows:

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

I think it is fine. But when I run it, I have this:

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 just wonder why the default code is wrong and how to make the defauly code right.

Ancestor answered 1/12, 2013 at 15:59 Comment(0)
U
15

You may have another option.

You can also add widgets in your .pro file like

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

By adding this line in .pro file, Now you just no need to worry about Qt version and include file like <QtGui/QMainWindow> or <QtWidgets/QMainWindow>

Hope it will useful to you.

Undercast answered 26/3, 2014 at 7:27 Comment(2)
Can you post your .pro file code with error/problem, so I can help you.Undercast
For Qt 5.10 on MacOS only <QtWidgets/QMainWindow> worked for me. QtGui seems has been deprecated.Librium
F
2

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

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

the error appears. It seems like QT_VERSION does not defined correctly. But if I move this code to the .cpp file, it is all right. The problem was solved as follows:
1. Add to the .pro file this:

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

2. Add to the .h file this:

    #ifdef HAVE_QT5
    #include <QtWidgets/QMainWindow>
    #else
    #include <QtGui/QMainWindow>
    #endif
Fanchette answered 25/7, 2017 at 19:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.