Important: Please read the Qt Code of Conduct -

"nullptr" was not declared in scope

  • Hi
    I am a beginner and currently I am working on a program.
    I have a main class called "FenPrincipale" of daughter classes "FenCene" and "FenCenep".

    My IDE sends me the following error at fencen.h and fencenep.h

    "nullptr was not declared in the scope"
    "identify 'nullptr' is a keyword in C ++ [-wc ++ 0x-compat]

    The notification is the same in the headers of the two classes.

    Here is the code of fencene.h

    #ifndef FENCENE_H
    #define FENCENE_H
    #include <QObject>
    #include <QWidget>
    namespace Ui {
    class FenCene;
    class FenCene : public QWidget
        explicit FenCene(QWidget *parent = nullptr);
        Ui::FenCene *ui;
    #endif // FENCENE_H

    Here is the code of fencenep.h

    #ifndef FENCENEP_H
    #define FENCENEP_H
    #include <QWidget>
    namespace Ui {
    class FenCenep;
    class FenCenep : public QWidget
        explicit FenCenep(QWidget *parent = nullptr);
        Ui::FenCenep *ui;
    #endif // FENCENEP_H

    Here is the code of fenprincipale.h

    #include <QMainWindow>
    #include <QWidget>
    #include <QStackedWidget>
    #include "fencene.h"
    #include "fencenep.h"
    namespace Ui {
    class FenPrincipale;
    class FenPrincipale : public QMainWindow
        explicit FenPrincipale(QWidget *parent = 0);
        Ui::FenPrincipale *ui;
        QWidget *fencen;
        QStackedWidget *centralfencen;
    public slots:
        void Affichefencene();
        void Affichefencenep();
    #endif // FENPRINCIPALE_H

    What can I do to fix the problem?

    Thank you in advance....

  • This might help:

    Are you running an old project or something new?
    What version of Qt are you running? 5.12?

    Most new projects should have CONFIG += c++11 defined already in PRO file.

  • I'm running a new project.
    I am using Qt version 5.1.0

    What else can I do?

  • 5.1.0 is really old. I would get 5.12 for new projects. I am not sure if 5.1.0 had support for c++11 by default.

  • @fcarney
    The problem is that I do not know how to update my Qt from version 5.1.0 to 5.1.2 ...

  • Lifetime Qt Champion

    @Nafab213 Did you add CONFIG += c++11 to your pro file as @fcarney suggested? nullptr requires C++11 compiler and when using GCC you need activate C++11. What is the compiler version?

    "The problem is that I do not know how to update my Qt from version 5.1.0 to 5.1.2" - how did you install Qt?

  • Lifetime Qt Champion


    To add to my fellows: the suggestion is to update to 5.12 not 5.1.2.

Log in to reply