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.
  • PadawanP Offline
    PadawanP Offline
    Padawan
    wrote on last edited by
    #1

    https://github.com/TruePadawan/Notepad--
    I have a simple text-editor program I'm working on. It has a feature where you simply click on a button and the current Qt/C++ code gets pasted on pastebin.

    Previously it gets my pastebin API key from a txt file but thats trash so I made a basic proxy server and made it get the key from there, but now it crashes on exit. If I comment out the API key request process, it doesnt crash on exit.

    header file - https://pastebin.com/CqGiZQVN
    definition - https://pastebin.com/5ihnR5wV

    I think the problem has to do with QNetworkReply or because I ran the program on Win7 because someone else ran it on win10 and it didnt crash on exit. So any idea on what the problem could be?

    Ningen

    jsulmJ 1 Reply Last reply
    0
    • PadawanP Padawan

      https://github.com/TruePadawan/Notepad--
      I have a simple text-editor program I'm working on. It has a feature where you simply click on a button and the current Qt/C++ code gets pasted on pastebin.

      Previously it gets my pastebin API key from a txt file but thats trash so I made a basic proxy server and made it get the key from there, but now it crashes on exit. If I comment out the API key request process, it doesnt crash on exit.

      header file - https://pastebin.com/CqGiZQVN
      definition - https://pastebin.com/5ihnR5wV

      I think the problem has to do with QNetworkReply or because I ran the program on Win7 because someone else ran it on win10 and it didnt crash on exit. So any idea on what the problem could be?

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

      @Padawan said in App crashes due to QNetworkReply:

      So any idea on what the problem could be?

      Please also provide a stack trace after the crash.

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

      1 Reply Last reply
      1
      • PadawanP Offline
        PadawanP Offline
        Padawan
        wrote on last edited by
        #3

        Is this helpful?

        trace.JPG

        Ningen

        Pl45m4P 1 Reply Last reply
        0
        • PadawanP Padawan

          Is this helpful?

          trace.JPG

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

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


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          PadawanP 1 Reply Last reply
          0
          • JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            You need to initialize all variables as well, especially on Windows.
            QNetworkAccessManager *manager{};
            //QNetworkReply *pasteData{};
            //QNetworkReply *apiData{};

            Christian EhrlicherC 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              You need to initialize all variables as well, especially on Windows.
              QNetworkAccessManager *manager{};
              //QNetworkReply *pasteData{};
              //QNetworkReply *apiData{};

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

              @JoeCFD said in App crashes due to QNetworkReply:

              especially on Windows.

              This is wrong - you always have to initialize your variables...

              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
              1
              • Christian EhrlicherC Christian Ehrlicher

                @JoeCFD said in App crashes due to QNetworkReply:

                especially on Windows.

                This is wrong - you always have to initialize your variables...

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

                @Christian-Ehrlicher On Linux the default value is nullptr. It is a good habit to initialize them with nullptr all the time.

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @JoeCFD said in App crashes due to QNetworkReply:

                  On Linux the default value is nullptr.

                  No, it is not.

                  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
                  2
                  • Christian EhrlicherC Christian Ehrlicher

                    @JoeCFD said in App crashes due to QNetworkReply:

                    On Linux the default value is nullptr.

                    No, it is not.

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

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

                    KroMignonK 1 Reply Last reply
                    0
                    • 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