void SomeClass::someMethod(somedata){...static QHash<QString,FeederState> feederStateHash; if(feederStateHash.isEmpty()) { feederStateHash[valuename_powp_fider_low_u]=fsLowVoltage; feederStateHash[valuename_powp_fider_norm_u]=fsNormalVoltage; feederStateHash[valuename_powp_fider_high_u]=fsHighVoltage; feederStateHash[valuename_powp_fider_faza_u]=fsFazeOffset; feederStateHash[valuename_powp_fider_is]=fsPresent; } FeederState _fstate = feederStateHash.value(value,fsError); ...}
class SomeClass{private: static QHash<QString,int> fhash;};
C++ (Qt)// .cpp#include... QHash<QString, int> SomeClass::feederStateHash; SomeClass::SomeClass() { ... } void SomeClass::someMethod(somedata){... if (feederStateHash.isEmpty()) { feederStateHash[valuename_powp_fider_low_u]=fsLowVoltage; feederStateHash[valuename_powp_fider_norm_u]=fsNormalVoltage; feederStateHash[valuename_powp_fider_high_u]=fsHighVoltage; feederStateHash[valuename_powp_fider_faza_u]=fsFazeOffset; feederStateHash[valuename_powp_fider_is]=fsPresent; } FeederState _fstate = feederStateHash.value(value,fsError); ...}
// static function in cpp filestatic QHash<QString, int> getHash(){ QHash<QString, int> feederStateHash; feederStateHash[valuename_powp_fider_low_u]=fsLowVoltage; feederStateHash[valuename_powp_fider_norm_u]=fsNormalVoltage; feederStateHash[valuename_powp_fider_high_u]=fsHighVoltage; feederStateHash[valuename_powp_fider_faza_u]=fsFazeOffset; feederStateHash[valuename_powp_fider_is]=fsPresent; return feederStateHash;} // static field initialization, called before main()QHash<QString, int> SomeClass::feederStateHash = getHash();