Warning when initializing data members

  • Hi,
    When I initialize data members such as

    QLineEdit *LineEdit_Name = new QLineEdit;

    I get the following warning:
    warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
    QLineEdit *LineEdit_Name = new QLineEdit;

    Any idea why?
    Thank you.

  • Lifetime Qt Champion

    Are you trying to do it directly in the class like:

    class MyClass
            QLineEdit *LineEdit_Name = new QLineEdit;

    Do the initialisation in the constructor of your class.
    Or activate C++11 support like the error message suggests (add CONFIG += c++11 to the PRO file).

  • Thank you.

Log in to reply