1. use extern
-
// globalvar.h
-
-
#ifndef MYGLOBALS
-
#define MYGLOBALS
-
-
extern int variable1;
-
extern int variable2;
-
-
#endif
-
-
...
-
-
// globalvar.cpp implementation
-
-
int variable1 = 0;
-
int variable = 0;
2.use global property in main.cpp
-
..
-
...
-
main (... )
-
{
-
...
-
a. setProperty ( "my_global_string" , my_global_string ) ;
-
...
-
MyClass my_class ;
-
...
-
-
return a. exec ( ) ;
-
-
}
-
MyClass :: MyClass ( )
-
{
-
...
-
qDebug ( ) << qApp -> property ( "my_global_string" ) ;
-
...
-
}