Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)
Forum Updated to NodeBB v4.3 + New Features

code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    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?

    Kind Regards,
    Sy

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #5

      The problem doesn't exist when changing the types to char*.

      Kind Regards,
      Sy

      J.HilkJ 1 Reply Last reply
      0
      • SPlattenS SPlatten

        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?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @SPlatten Can you show one of these failing initialisations?

        Note: it is unusual to provide direct access to m_* fields as m_ usually is a prefix for private fields.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • SPlattenS SPlatten

          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?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #3

          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/8

          C++ 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


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          4
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #4

            I'm thinking that now if I was to change these to use basic data types like char[], it wouldn't be a problem. I'll try and report back.

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #5

              The problem doesn't exist when changing the types to char*.

              Kind Regards,
              Sy

              J.HilkJ 1 Reply Last reply
              0
              • SPlattenS SPlatten

                The problem doesn't exist when changing the types to char*.

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #6

                @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.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                2
                • SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  I've changed these now, access functions are used to return QString's of the concatenated strings.

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved