Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
In QT, I have a class called MainWindow. I have a variable called plotGrpahics declared as static in my header MainWindow.h file: class MainWindow : public QMainWindow { static QGraphicsScene * plotGrpahics; } However the variable is not seen in my MainWindow.cpp file until I re-declare it there like this: QGraphicsScene * MainWindow::plotGrpahics; The variable is then initialized in the run-time inside the MainWindow constructor: plotGrpahics = new QGraphicsScene(); Now this actually works perfectly, but I don't know why I have to declare it twice!! 1- Of course the .h is included in the .cpp. 2- I checked that they are both the same variable in runtime, and when I delete either the .h definition or the .cpp definition, the code does not compile! 3- It is also not an access modifier issue, this happens with both public and private static variables. 4- As you can see, it not an initialization issue.