[SOLVED] Crash right at instancing QMainWindow inheriting class
-
Hey guys,
so I've written a program with Qt, c++ and openGL and wanted to add support for my Oculus Rift DK. To get an overview, I used "this code":http://pastebin.com/2VEasjbu, rewrote parts of it and tried to get my application to run.
Since I did that, it just crashes on startup. For debugging purposes, I'm calling qDebug() everytime I enter and leave any function and between steps.
My main.cpp file looks like this:@#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{
qDebug() << "main.cpp Start!";
QApplication a(argc, argv);
qDebug() << "vor MainWindow w";
MainWindow w;
qDebug() << "vor w.show()";
w.show();return a.exec(); qDebug() << "main.cpp Ende";
}@
It just runs up to the "vor MainWindow w" message before crashing (with an access violation).
My question is: where might that violation be? In the MainWindow constructor? Because that one also has qDebug() messages in it which are never even reached. Could it still be responsible or has it got to be something in my header file (mainwindow.h) or something?
Thanks a lot in advance! -
Could you show MainWindow constructor.
-
what about starting your app in debug mode, if it crashes your should see a full backtrace where exactly the crash happens!?
If your have some member variables that are created on the stack in your main window it might also crash there, so hard to say without the code.
-
Unfortunately, my code is a huge mess (and at work, had to leave early today). I will get back to that on monday.
Starting in debug mode means having a debugger set up? I couldn't do that so far since I have no rights on my work computer. I'll see to get one though.
Thanks so far! -
yeah of course you need a c++ debugger to start in debug mode, but that depends on the platform and compiler your are using.. usually you can use the default debugger unless you are using the MSVC compiler, I never figured out how to install a debugger for that. In that case I just switched to MinGW on windows there is a debugger included.
-
It's the constructor or the call to the constructor.
Because the MainWindow is also a QObject subclass and when using Designer it also includes some ui derived classes.
You might want to show the constructor? -
Jeroentje: As far I know the crash can also happen in the class' member initialization.
e.g.
@
class ABC {
public:
ABC() {} // may crash here
private:
XYZ xyz; // or constructor call of XYZ here may also crash
}
@
if the constructor of a member variables crashes the body of the own constructor is never called. OP said he had debug messages in his constructor and if they never get printed that might be the issue!? -
Xander84: Yes I'm using the MSVC compiler. Couldn't get a debugger to work with it too.
Anyway, solution to my problem was an error in the Oculus SDK - if you try to instanciate a sensorfusion object without calling system::init first or instanciate a system object, you're gonna have a bad time. :)