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. small console program keeps crashing for some unknown reason
Forum Updated to NodeBB v4.3 + New Features

small console program keeps crashing for some unknown reason

Scheduled Pinned Locked Moved Solved General and Desktop
qtcreator
20 Posts 3 Posters 4.3k 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.
  • D Dn588

    @jsulm Thanks I see now that it crashes on line 189 of Qatomic_x86.cpp. What does this mean? I also see that the processDirectory and getChecksum functions has no issue however this crash happens before getDuplicateList runs?
    the reason I use pointers is that I get an error message when trying to pass a QFile as argument to generateChecksum

    here's a link to my code if it helps to see it in QTCreator:

    https://www.sendspace.com/file/pay7cb

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

    @Dn588 What error do you get if you pass QFile to generateChecksum?
    It should be like this:

    QByteArray FileChecker::generateChecksum(QFile& file) // Change QFile* to QFile&
    {
    ...
    }
    

    This are C++ basics.
    And again if you want to use pointer then you have to create an instance using new and later delete it. But in your case there is really no need for pointers - just fix your interface to pass QFile as reference. And even if you want to pass a pointer you can do so:

    QFile file;
    ...
    generateChecksum(&file);
    

    I'm quite sure the problem is not in QAtomic. You should take a look at the call stack who is calling QAtomic?
    At which line in your code does it crash?

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

    D 1 Reply Last reply
    2
    • jsulmJ jsulm

      @Dn588 What error do you get if you pass QFile to generateChecksum?
      It should be like this:

      QByteArray FileChecker::generateChecksum(QFile& file) // Change QFile* to QFile&
      {
      ...
      }
      

      This are C++ basics.
      And again if you want to use pointer then you have to create an instance using new and later delete it. But in your case there is really no need for pointers - just fix your interface to pass QFile as reference. And even if you want to pass a pointer you can do so:

      QFile file;
      ...
      generateChecksum(&file);
      

      I'm quite sure the problem is not in QAtomic. You should take a look at the call stack who is calling QAtomic?
      At which line in your code does it crash?

      D Offline
      D Offline
      Dn588
      wrote on last edited by
      #10

      @jsulm I put a breakpoint at the end of generateChecksum and the program gets there with no issues so i'm guessing the processDirectory and generateChecksum functions are ok? So the crash happens after generateChecksum but i'm not exactly sure where. Where can I view the calling stack?

      I get the following error when debugging
      "The inferior stopped because it received a signal from the operating system
      signal name: SIGSEGV
      signal meaning: segmentation fault
      "

      Yes sorry I should have passed by reference from the start. Seems like 6 month's break from C++ made me forget quite a lot...

      Thanks again for all your help/patience

      1 Reply Last reply
      0
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #11

        Fix like this to not to crash:

        QByteArray FileChecker::generateChecksum(QFile* file) {
        
            if(file->open(QIODevice::ReadOnly)) {
                QCryptographicHash cHash(QCryptographicHash::Md5);
                cHash.addData(file->readAll());
                QByteArray checksum = cHash.result();
                return checksum;
            }
        
            // This line was missing, so you did not return a valid QByteArray instance if the if condition was false!
            return QByteArray();
        }
        

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

        D 1 Reply Last reply
        1
        • jsulmJ jsulm

          Fix like this to not to crash:

          QByteArray FileChecker::generateChecksum(QFile* file) {
          
              if(file->open(QIODevice::ReadOnly)) {
                  QCryptographicHash cHash(QCryptographicHash::Md5);
                  cHash.addData(file->readAll());
                  QByteArray checksum = cHash.result();
                  return checksum;
              }
          
              // This line was missing, so you did not return a valid QByteArray instance if the if condition was false!
              return QByteArray();
          }
          
          D Offline
          D Offline
          Dn588
          wrote on last edited by
          #12

          @jsulm Thanks that worked!. However now it seems like the file i'm passing to generateChecksum has no fileName? I get 12 errors in the terminal saying " QFSFileEngine::open no file name specified". the directory I am entering has 4 .dat files which consists of 2 groups of 2 duplicate files. Any idea what is happening here? Also where can I view the calling stack in future if I have a crash like before?

          mrjjM jsulmJ 3 Replies Last reply
          0
          • D Dn588

            @jsulm Thanks that worked!. However now it seems like the file i'm passing to generateChecksum has no fileName? I get 12 errors in the terminal saying " QFSFileEngine::open no file name specified". the directory I am entering has 4 .dat files which consists of 2 groups of 2 duplicate files. Any idea what is happening here? Also where can I view the calling stack in future if I have a crash like before?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #13

            @Dn588
            Call stack

            1 Reply Last reply
            0
            • D Dn588

              @jsulm Thanks that worked!. However now it seems like the file i'm passing to generateChecksum has no fileName? I get 12 errors in the terminal saying " QFSFileEngine::open no file name specified". the directory I am entering has 4 .dat files which consists of 2 groups of 2 duplicate files. Any idea what is happening here? Also where can I view the calling stack in future if I have a crash like before?

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

              @Dn588 Debug your application step by step and see what happens and what is wrong.

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

              D 1 Reply Last reply
              0
              • D Dn588

                @jsulm Thanks that worked!. However now it seems like the file i'm passing to generateChecksum has no fileName? I get 12 errors in the terminal saying " QFSFileEngine::open no file name specified". the directory I am entering has 4 .dat files which consists of 2 groups of 2 duplicate files. Any idea what is happening here? Also where can I view the calling stack in future if I have a crash like before?

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

                @Dn588 The problem is: you pass only the file name without the directory. So your application tries to open that file in current directory. You can see it easily if you debug.

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

                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Dn588 Debug your application step by step and see what happens and what is wrong.

                  D Offline
                  D Offline
                  Dn588
                  wrote on last edited by
                  #16

                  Thanks @jsulm Will do:) is therre a way to view the contents of a variable while debugging? I google'd that error and it seems like it happens when the QFile is initialized with a name so I used QFile->setFileName(fileList.at(i)) but still no luck... Sorry for all the excessive questions... i'm writing two exams tomorrow and on mon and have this program to finish before mon to get an internship interview so stressing a bit...

                  mrjjM jsulmJ 2 Replies Last reply
                  0
                  • D Dn588

                    Thanks @jsulm Will do:) is therre a way to view the contents of a variable while debugging? I google'd that error and it seems like it happens when the QFile is initialized with a name so I used QFile->setFileName(fileList.at(i)) but still no luck... Sorry for all the excessive questions... i'm writing two exams tomorrow and on mon and have this program to finish before mon to get an internship interview so stressing a bit...

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #17

                    @Dn588 said:

                    contents of a variable while debugging?

                    See picture. its on right side. showing Name / Value / type
                    and "this" variable.

                    1 Reply Last reply
                    0
                    • D Dn588

                      Thanks @jsulm Will do:) is therre a way to view the contents of a variable while debugging? I google'd that error and it seems like it happens when the QFile is initialized with a name so I used QFile->setFileName(fileList.at(i)) but still no luck... Sorry for all the excessive questions... i'm writing two exams tomorrow and on mon and have this program to finish before mon to get an internship interview so stressing a bit...

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

                      @Dn588 Please take a closer look at the picture @mrjj provided - in the upper right corner you will find what you're looking for.
                      Setting only the file name is not enough if the file is not in current directory. You need to set whole path: the directory you use with QDir + file name.

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

                      D 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @Dn588 Please take a closer look at the picture @mrjj provided - in the upper right corner you will find what you're looking for.
                        Setting only the file name is not enough if the file is not in current directory. You need to set whole path: the directory you use with QDir + file name.

                        D Offline
                        D Offline
                        Dn588
                        wrote on last edited by
                        #19

                        @jsulm Sorry I see that's possible in the call stack. Sorry I have an eye problem and as a result only have 4% vision so missed it the first time...

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          Dn588
                          wrote on last edited by
                          #20

                          Thanks again @mrjj and @jsulm for all help.

                          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