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. QFile::open() crashes application on call to previously written file
Forum Updated to NodeBB v4.3 + New Features

QFile::open() crashes application on call to previously written file

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 6 Posters 1.8k Views 3 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.
  • P Offline
    P Offline
    Pollarm
    wrote on last edited by
    #5

    Is this the appropriate information? Sorry for the mistakes and inaccuracy, I've never done this before...

    1 NtCreateFile ntdll 0x7ffae728d0c4
    2 CreateFileW KERNELBASE 0x7ffae4d62920
    3 CreateFileW KERNELBASE 0x7ffae4d62646
    4 QFSFileEngine::link Qt5Core 0x7ffa6f27fe4a
    5 QFSFileEngine::open Qt5Core 0x7ffa6f250ca9
    6 QFile::open Qt5Core 0x7ffa6f227efb
    7 Roto 0x7ff656965bab
    8 Roto 0x7ff6569747ec
    9 Roto 0x7ff656976d4c
    10 QObject::qt_static_metacall Qt5Core 0x7ffa6f2f5109
    11 QAction::activate Qt5Widgets 0x7ffa74285eaf
    12 QMenu::actionGeometry Qt5Widgets 0x7ffa743de378
    13 QMenu::actionGeometry Qt5Widgets 0x7ffa743de153
    14 QMenu::mouseReleaseEvent Qt5Widgets 0x7ffa743e38b1
    15 QWidget::event Qt5Widgets 0x7ffa742b89a2
    16 QMenu::event Qt5Widgets 0x7ffa743df927
    17 QApplicationPrivate::notify_helper Qt5Widgets 0x7ffa742956f0
    18 QApplication::notify Qt5Widgets 0x7ffa7429361d
    19 QCoreApplication::notifyInternal2 Qt5Core 0x7ffa6f2d51ca
    20 QApplicationPrivate::sendMouseEvent Qt5Widgets 0x7ffa742968f3
    21 QSizePolicy::QSizePolicy Qt5Widgets 0x7ffa742e0f7b
    22 QSizePolicy::QSizePolicy Qt5Widgets 0x7ffa742df53e
    23 QApplicationPrivate::notify_helper Qt5Widgets 0x7ffa742956f0
    24 QApplication::notify Qt5Widgets 0x7ffa74294768
    25 QCoreApplication::notifyInternal2 Qt5Core 0x7ffa6f2d51ca
    26 QGuiApplicationPrivate::processMouseEvent Qt5Gui 0x7ffa73bf5144
    27 QWindowSystemInterface::sendWindowSystemEvents Qt5Gui 0x7ffa73bdfe29
    28 QEventDispatcherWin32::processEvents Qt5Core 0x7ffa6f31f887
    29 qt_plugin_query_metadata qwindows 0x7ffaac128d89
    30 QEventLoop::exec Qt5Core 0x7ffa6f2d130c
    31 QCoreApplication::exec Qt5Core 0x7ffa6f2d4194
    32 Roto 0x7ff65696e857
    33 Roto 0x7ff656983027
    34 Roto 0x7ff6569825ce
    35 BaseThreadInitThunk KERNEL32 0x7ffae5267034
    36 RtlUserThreadStart ntdll 0x7ffae723d241

    I'm not sure why it's not grabbing line numbers as well, that field is blank in all rows.

    1 Reply Last reply
    0
    • nageshN Offline
      nageshN Offline
      nagesh
      wrote on last edited by
      #6

      @Pollarm check whether file is successfully opened(return value of open) before accessing it.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pollarm
        wrote on last edited by Pollarm
        #7

        Hello all,

        I've also seen while messing with it that calling file.remove() also causes this behavior.

        Is it possible that perhaps there is some kind of corruption in the file, so that when QFile tries to access it this behavior occurs? Just guessing. That seems unlikely to me, because I can open files with QIODevice::ReadOnly in my method that reads the data from the file to reconstruct the project, it only crashes when opened with file.open(QIODevice::WriteOnly).

        Thanks

        1 Reply Last reply
        0
        • nageshN Offline
          nageshN Offline
          nagesh
          wrote on last edited by
          #8

          @Pollarm Did you check file open return value?
          QFile file(projectName);
          if(file.open(QIODevice::WriteOnly))
          {
          QDataStream out(&file); // we will serialize the data into the file
          }
          else
          {
          //Failed to open the file
          }

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pollarm
            wrote on last edited by
            #9

            Hello @nagesh,

            I did try that, and it crashed, I believe inside the if-statement.

            Thanks

            1 Reply Last reply
            0
            • nageshN Offline
              nageshN Offline
              nagesh
              wrote on last edited by
              #10

              @Pollarm use debugger breakpoint to check which line it crashed?

              It only crashes when it is used on a file that was previously passed through this method.
              

              open the file which was saved using this method through explorer and check whether it's having any content?

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Pollarm
                wrote on last edited by
                #11

                I'm pretty sure that it crashes on the line that calls

                file.open(QIODevice::WriteOnly)
                

                And I have confirmed the file contains the appropriate content.

                Thanks

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Pollarm
                  wrote on last edited by
                  #12

                  I was able to catch an exception code 0xc0000409, which I've seen means STATUS_STACK_BUFFER_OVERRUN. What could I do that gets around this?

                  If that is the case, does that mean that this is not a QT issue after all?

                  kshegunovK 1 Reply Last reply
                  0
                  • P Pollarm

                    I was able to catch an exception code 0xc0000409, which I've seen means STATUS_STACK_BUFFER_OVERRUN. What could I do that gets around this?

                    If that is the case, does that mean that this is not a QT issue after all?

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by kshegunov
                    #13

                    @Pollarm said in QFile::open() crashes application on call to previously written file:

                    If that is the case, does that mean that this is not a QT issue after all?

                    It doesn't, but I'd be rather surprised this to be a bug in the Qt codebase. Did you extract the above stack trace (the one you posted) from the point of the crash, or did you just stop the debugger there at another time? If the stack was not from a crash, you should reproduce the crash in the debugger and when it happens extract it. Aside from that there are 2 typical reasons for such an error:

                    1. You're running an infinite recursion, you should check this. For example it may be a slot calling itself indirectly (through a signal).

                    or

                    1. You've corrupted the stack somewhere without realizing. Writing to a buffer in the stack over its allowed boundaries should do it. Do you have char data[someSize] anywhere you may be saving to, or something of that sort?

                    It'd be also helpful to see some more code around the point of crash, would you provide how you read the file, what you save from it, etc.

                    PS. Btw, it doesn't appear your application (assuming Roto is your app) contains debug information. You should build in debug before testing anything else.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    4
                    • P Offline
                      P Offline
                      Pollarm
                      wrote on last edited by
                      #14

                      @kshegunov I believe I've identified the source of the overflow:

                      My parameters are being written incorrectly because for some reason (completely unrelated issue) and its causing large values, 9 digits, to be pushed as in index to an array that I think can only hold a maximum of around 57.

                      Your comment helped me track that down, thanks!!

                      JKSHJ 1 Reply Last reply
                      0
                      • P Pollarm

                        @kshegunov I believe I've identified the source of the overflow:

                        My parameters are being written incorrectly because for some reason (completely unrelated issue) and its causing large values, 9 digits, to be pushed as in index to an array that I think can only hold a maximum of around 57.

                        Your comment helped me track that down, thanks!!

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #15

                        @Pollarm said in QFile::open() crashes application on call to previously written file:

                        My parameters are being written incorrectly because for some reason (completely unrelated issue) and its causing large values, 9 digits, to be pushed as in index to an array that I think can only hold a maximum of around 57.

                        If you replace the C arrays with std::vector or QVector, this type of error will be caught immediately when your code is built and run in Debug mode.

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        1 Reply Last reply
                        2
                        • P Offline
                          P Offline
                          Pollarm
                          wrote on last edited by
                          #16

                          Hello all,

                          Sorry for the long delay in response, I had other issues in this project to work on. The solution to this issue was found, I was using my own extension for the files and it was making windows antivirus grab the files and scan them. Changing the extension to a simple .txt circumvented this issue. Thanks all for your help on this.

                          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