Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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
    {
        Q_OBJECT
    
    public:
        explicit FenCene(QWidget *parent = nullptr);
        ~FenCene();
    
    private:
        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
    {
        Q_OBJECT
    
    public:
        explicit FenCenep(QWidget *parent = nullptr);
        ~FenCenep();
    
    private:
        Ui::FenCenep *ui;
    };
    
    #endif // FENCENEP_H
    
    

    Here is the code of fenprincipale.h

    #ifndef FENPRINCIPALE_H
    #define FENPRINCIPALE_H
    
    #include <QMainWindow>
    #include <QWidget>
    #include <QStackedWidget>
    #include "fencene.h"
    #include "fencenep.h"
    
    
    namespace Ui {
    class FenPrincipale;
    }
    
    class FenPrincipale : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit FenPrincipale(QWidget *parent = 0);
        ~FenPrincipale();
    
    private:
        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:
    https://stackoverflow.com/questions/16509932/using-qt-creator-c-11-nullptr-is-keyworded

    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?
    Thanks



  • 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 ...


  • Qt Champions 2019

    @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

    Hi,

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


Log in to reply