One header file to be used only once in whole program
Unsolved
C++ Gurus
-
I have header file named
simple.h
Suppose with messageBox and one variablecalledVariable
fetched from database in constructor
(THIS VARIABLE IS NEVER GONNA CHANGE)It is used in another header file
name.h
And this header file is used in many files
#include"simple.h"
In 10 files.
Here when I do this I get 10 message box with same thing. What I want is to
callsimple.h
ONLY once. and get the same variable valuecalledVariable
which we will get in the first execution -
@Thank-You Declare the variable es extern in the header file and define it once somewhere in a C++ file.
See https://en.cppreference.com/w/cpp/language/storage_duration for details.
But keep in mind that QObject based classes are not allowed to be instantiated before QApplication instance is created!