Results 1 to 10 of 10

Thread: Access Violation - Crashing Application

  1. #1
    Join Date
    Oct 2010
    Posts
    11

    Default Access Violation - Crashing Application

    Qt Code:
    1. #ifndef TIMERWINDOW_H
    2. #define TIMERWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QMenu>
    6. #include <QAction>
    7. #include <QMenuBar>
    8.  
    9. class TimerWindow : public QMainWindow
    10. {
    11. Q_OBJECT
    12. private:
    13. QMenu* File_Menu;
    14. public:
    15. explicit TimerWindow(QWidget *parent = 0); signals:
    16.  
    17. public slots:
    18.  
    19. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "TimerWindow.h"
    2.  
    3. TimerWindow::TimerWindow(QWidget *parent) : QMainWindow(parent)
    4. {
    5. File_Menu = menuBar()->addMenu("Test");
    6. }
    To copy to clipboard, switch view to plain text mode 

    I have simplified my code and tested the above I am not sure what I am doing wrong here. It continues to crash on start over and over. Anyone have ideas on what I have done wrong?

    Error String: exited with code -1073741819

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access Violation - Crashing Application

    Convert the error code to hex and search through the msdn to find out what that error code means. Then you can decide what should be done next (with some help from us, maybe).
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Oct 2010
    Posts
    11

    Default Re: Access Violation - Crashing Application

    I've done this, the error-code means there is an access violation. Everything I read says that it has to do with accessing memory without the proper privileges. However, unless I am missing something, the code is proper.

    [0xC0000005]

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Access Violation - Crashing Application

    Have you single-stepped your program to find which line triggers the crash. We don't have your startup code so we would only be guessing.

    Access violation: typically caused by dereferencing a null or otherwise invalid pointer.

  5. #5
    Join Date
    Oct 2010
    Posts
    11

    Default Re: Access Violation - Crashing Application

    File_Menu = menuBar()->addMenu("Test");

    That is the line that crashes. It will run fine without that line. I have tried also changing it to:

    File_Menu = new QMenu();

    That crashes as well.

    I also tried doing a local variable, it works fine. I tried changing the name of the "File_Menu" variable, it had no affect. I just don't understand what happened here.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access Violation - Crashing Application

    We need more code - is menuBar() returning a valid pointer?

  7. #7
    Join Date
    Oct 2010
    Posts
    11

    Default Re: Access Violation - Crashing Application

    Also:

    File_Menu = NULL; //Changing to this also causes an error.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Access Violation - Crashing Application

    Quote Originally Posted by squidge View Post
    We need more code - is menuBar() returning a valid pointer?
    It should be, the QMainWindow::menuBar() say it will create an empty menu bar if one does not exist.
    Quote Originally Posted by LIRiot View Post
    File_Menu = NULL; //Changing to this also causes an error.
    This makes no sense. You should clean and rebuild the source because clearly there is some major internal disconnect.

  9. #9
    Join Date
    Oct 2010
    Posts
    11

    Default Re: Access Violation - Crashing Application

    *Sigh*

    Copied all the source and rebuilt it all from a new project and it fixed. Any ideas what would cause this to happen? Is there an easier way to fix such problems? Is there a file I can delete to force it to rebuild, or perhaps an option in the interface?

  10. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Access Violation - Crashing Application

    Yes, use "make clean", "Build, Rebuild All" in Qt Creator, or the equivalent in Visual Studio. If you are using a shadow build area, just delete the shadow build directory.

    There is possibly a runtime dependency between some of your code modules and the TimerWindow class that is not captured as source dependency. Changing the TimerWindow source has not caused the rebuild of the dependent module: the dependent module is expecting one binary arrangement of code, and the module is presenting another.

Similar Threads

  1. Access Violation with VS2008
    By Takatschio in forum Qt Programming
    Replies: 3
    Last Post: 19th August 2010, 09:16
  2. QModelIndexList access reading violation
    By Daxos in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2010, 08:32
  3. OpenCV causes access violation only during timerEvent
    By derekkingston in forum Qt Programming
    Replies: 5
    Last Post: 19th February 2010, 08:56
  4. Access violation when reading big text files
    By robertson1 in forum General Programming
    Replies: 0
    Last Post: 18th September 2008, 06:59
  5. Access Violation on Signal Emit
    By khagzan in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2007, 22:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.