code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)
-
I have a static const instance of QString defined in a class header, the class is called PSUApplication:
static const QString m_userDataRoot; static const QString m_xmlFolder;In the CPP file:
const QString PSUApplication::m_userDataRoot("./UserData"); const QString PSUApplication::m_xmlFolder(PSUApplication::m_userDataRoot + "xml/");I have a references in other cpp files that use these statics to initialise other objects, such as QString's to make up references and QDir's.
These all fail at run-time. Is there a way to resolve this?
-
I have a static const instance of QString defined in a class header, the class is called PSUApplication:
static const QString m_userDataRoot; static const QString m_xmlFolder;In the CPP file:
const QString PSUApplication::m_userDataRoot("./UserData"); const QString PSUApplication::m_xmlFolder(PSUApplication::m_userDataRoot + "xml/");I have a references in other cpp files that use these statics to initialise other objects, such as QString's to make up references and QDir's.
These all fail at run-time. Is there a way to resolve this?
-
I have a static const instance of QString defined in a class header, the class is called PSUApplication:
static const QString m_userDataRoot; static const QString m_xmlFolder;In the CPP file:
const QString PSUApplication::m_userDataRoot("./UserData"); const QString PSUApplication::m_xmlFolder(PSUApplication::m_userDataRoot + "xml/");I have a references in other cpp files that use these statics to initialise other objects, such as QString's to make up references and QDir's.
These all fail at run-time. Is there a way to resolve this?
Hi @SPlatten
like @kshegunov told me in my topic a long time ago:
https://forum.qt.io/topic/97838/static-const-qstring-implicit-sharing-issue/8C++ does not guarantee you order of initialization of statics
so m_xmlFolder relies on m_userDataRoot which probably does not exist at that moment int time
-
@SPlatten said in code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance):
The problem doesn't exist when changing the types to char*.
if the 2nd static variable is still depending on the first one, you will eventually run into trouble. Because the initialization order may now fit, but it could brake any moment.