Reputation: 33
sorry for my creepy english. In Qt 4.8.4 I'm try to create singleton class with static QString field. It cannot be const, because this field will change value at runtime. Initialization this field making by constant QString, declared at same file.
Unfortunately this is don't work and in string of initialization
LogWay = QString("file.txt");
program unexpectedly finish with mistake
The inferior stopped because it received a signal from the Operating System. Signal name: SIGSEGV Signal meaning : Segmentation fault
in file "qatomic_i386.h"
What i doing wrong? This code sample work with int, bool or double variables, but not with QString. Why? I tried write without QString constructor, use simple equating
LogWay = "...";
but i have same error. Thank for helping.
Full code of class:
this is .h file #include
const double _ACCURACY_ = 0.0001;
static const QString _LOG_WAY_ = "GrafPrinterLog.txt";
class GlobalSet
{
private:
static QSettings *_Settings;
GlobalSet(){}
GlobalSet(const GlobalSet&){}
GlobalSet &operator=(const GlobalSet&);
static GlobalSet *GS;
public:
static double IntToCut;
static double ReplaceSize;
static double Accuracy;
static int MaxPointCount;
static bool NeedProper;
static QString LogWay;
~GlobalSet();
static GlobalSet *Instance()
{
if (GS == NULL)
{
GS = new GlobalSet();
GS->firstSetUp();
}
return GS;
}
void firstSetUp()
{
Accuracy = _ACCURACY_;
LogWay = QString("file.txt");//fail is here!
NeedProper = false;
_Settings = new QSettings("options.ini",QSettings::IniFormat);
}
};
and this is .cpp file
#include "globalset.h"
GlobalSet *GlobalSet::GS = NULL;
QSettings *GlobalSet::_Settings = NULL;
double GlobalSet::Accuracy = _ACCURACY_;
QString GlobalSet::LogWay = _LOG_WAY_;
Upvotes: 2
Views: 5018
Reputation: 22346
It could be "static order initialisation fiasco" (see here), because you are trying to create a static QString
from another static QString
.
Upvotes: 5