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. App crashes due to QNetworkReply
Forum Updated to NodeBB v4.3 + New Features

App crashes due to QNetworkReply

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 7 Posters 1.6k Views 2 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.
  • Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by Christian Ehrlicher
    #10

    Just because it does print 0 here it does not mean it's correctly initialized - it's by accident because your stack where aaa points to is currently filled with zeros. A good memory analyzer like e.g. valgrind will tell you that you're accessing uninitialized data.

    See https://godbolt.org/z/9vsrva15a - myPtr is not initialized anywhere before usage.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    JoeCFDJ 1 Reply Last reply
    4
    • JoeCFDJ JoeCFD

      @Christian-Ehrlicher
      double * aaa;
      std::cout << "aaa=" << aaa << std::endl;
      aaa=0

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #11

      @JoeCFD said in App crashes due to QNetworkReply:

      double * aaa;
      std::cout << "aaa=" << aaa << std::endl;
      aaa=0

      This is the best way to create an application with random crashes!
      Never use a uninitialized pointer.

      This is a very basic rule in C/C++.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      JoeCFDJ 1 Reply Last reply
      2
      • KroMignonK KroMignon

        @JoeCFD said in App crashes due to QNetworkReply:

        double * aaa;
        std::cout << "aaa=" << aaa << std::endl;
        aaa=0

        This is the best way to create an application with random crashes!
        Never use a uninitialized pointer.

        This is a very basic rule in C/C++.

        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #12

        @KroMignon I know. I always initialize all pointers.

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Just because it does print 0 here it does not mean it's correctly initialized - it's by accident because your stack where aaa points to is currently filled with zeros. A good memory analyzer like e.g. valgrind will tell you that you're accessing uninitialized data.

          See https://godbolt.org/z/9vsrva15a - myPtr is not initialized anywhere before usage.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #13

          @Christian-Ehrlicher You are right. I tried it in middle of my app and uninitialized pointers are dangled. My memory is getting worse. I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.

          JonBJ KroMignonK 2 Replies Last reply
          1
          • JoeCFDJ JoeCFD

            @Christian-Ehrlicher You are right. I tried it in middle of my app and uninitialized pointers are dangled. My memory is getting worse. I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #14

            @JoeCFD
            It's a C++ language thing, so not per-platform. What you may find, on any platform/compiler, is that there is a difference between what you find in uninitialized (stack) variables between debug versus release builds. Or that may apply to heap areas. It's all undefined :)

            1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @Christian-Ehrlicher You are right. I tried it in middle of my app and uninitialized pointers are dangled. My memory is getting worse. I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #15

              @JoeCFD said in App crashes due to QNetworkReply:

              I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.

              AFAIK, on Linux/GCC pointers are never initialized per default.
              On Windows/MSVC, they are set to 0 in debug build, but not in release.

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              JoeCFDJ Christian EhrlicherC 2 Replies Last reply
              2
              • KroMignonK KroMignon

                @JoeCFD said in App crashes due to QNetworkReply:

                I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.

                AFAIK, on Linux/GCC pointers are never initialized per default.
                On Windows/MSVC, they are set to 0 in debug build, but not in release.

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by
                #16

                @KroMignon Good to know. Thanks. I have not followed this for ages.

                1 Reply Last reply
                0
                • KroMignonK KroMignon

                  @JoeCFD said in App crashes due to QNetworkReply:

                  I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.

                  AFAIK, on Linux/GCC pointers are never initialized per default.
                  On Windows/MSVC, they are set to 0 in debug build, but not in release.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by Christian Ehrlicher
                  #17

                  @KroMignon said in App crashes due to QNetworkReply:

                  On Windows/MSVC, they are set to 0 in debug build, but not in release.

                  Wrong again - it's 0xCCCCCCCC or 0xCDCDCDCD
                  See https://en.wikipedia.org/wiki/Magic_number_(programming)#Debug_values

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  KroMignonK 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @KroMignon said in App crashes due to QNetworkReply:

                    On Windows/MSVC, they are set to 0 in debug build, but not in release.

                    Wrong again - it's 0xCCCCCCCC or 0xCDCDCDCD
                    See https://en.wikipedia.org/wiki/Magic_number_(programming)#Debug_values

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by KroMignon
                    #18

                    @Christian-Ehrlicher said in App crashes due to QNetworkReply:

                    Wrong again - it's 0xCCCCCCCC or 0xCDCDCDCD

                    Yes, I was wrong... sorry, too fare away.
                    I mixed up pointer initialization and variable initialization!!

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    1 Reply Last reply
                    1
                    • Pl45m4P Pl45m4

                      @Padawan

                      As the screenshot shows, you have a segfault here. Probably from accessing any invalid pointer.
                      You commented some lines?! Does it still crash when you run it like this?

                      For example; I've noticed that you deleteLater your apiData, but there is also a delete apiData in d'tor (commented but still there).

                      PadawanP Offline
                      PadawanP Offline
                      Padawan
                      wrote on last edited by
                      #19

                      @Pl45m4 It always crashes if the API Key Request process happens

                      Ningen

                      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