PDA

View Full Version : Access Violation - Crashing Application



LIRiot
5th December 2010, 20:01
#ifndef TIMERWINDOW_H
#define TIMERWINDOW_H

#include <QMainWindow>
#include <QMenu>
#include <QAction>
#include <QMenuBar>

class TimerWindow : public QMainWindow
{
Q_OBJECT
private:
QMenu* File_Menu;
public:
explicit TimerWindow(QWidget *parent = 0); signals:

public slots:

};




#include "TimerWindow.h"

TimerWindow::TimerWindow(QWidget *parent) : QMainWindow(parent)
{
File_Menu = menuBar()->addMenu("Test");
}

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

franz
5th December 2010, 20:15
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).

LIRiot
5th December 2010, 21:32
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]

ChrisW67
5th December 2010, 22:05
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.

LIRiot
5th December 2010, 22:31
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.

squidge
5th December 2010, 22:35
We need more code - is menuBar() returning a valid pointer?

LIRiot
5th December 2010, 22:35
Also:

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

ChrisW67
5th December 2010, 22:41
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.


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.

LIRiot
5th December 2010, 23:03
*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?

ChrisW67
5th December 2010, 23:10
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.