This is a simple example of what i am trying to achieve: I have a header file GlobalVar.h
#ifndef MY_GLOBALS_H
#define MY_GLOBALS_H
extern int flag;
#endif
A MainWindow.cpp
#include "Globalvar.h"
int flag;
void function() {
qDebug() <<"Flag is"<<flag;
}
A main.cpp
#include "GlobalVar.h"
int flag=0;
int main() {
if(true) {
flag=1;
qDebug() <<"Flag is"<<flag;
}
}
Now the console output shows the value of flag as : "Flag is 1" (In Line no:61) and "Flag is 0" (In Line no: 80).
This means that the flag has been set to 1 already when it reaches to the MainWindow.cpp then why does to shows the value of flag equal to 0 ?