3

I've been working on an application every day for a while, like a few weeks now, and have gotten pretty far in development.

I had an unnecessary class which was just forwarding an object creation. It was basically a "Window" class that created a "Widget" class. So instead of going through that unnecessary "Window" class to create the "Widget" class, I just created the "Widget" class directly in the main "App" class. But now if I run it, the app crashes as if it were in some recursive loop and doesn't show the window.

I added some QDebug messages on each line to see where it was getting to before crashing, and then it runs just fine. What the hell is going on here? it runs just fine like this:

void App::initialize()
{
    qDebug() << "Initializing...";

    qDebug() << "Creating the widget";
    widget = new Widget();

    qDebug() << "Showing the widget...";
    widget->show();

    qDebug() << "Initialized";
}

But if I remove any of the top two QDebug messages, it gets stuck in its recursive-like loop. I have no idea why it's doing this. I've checked the project files and qmake, ran in both debug and release mode and its all the same.

I'm not looking for an answer on how to fix this. What I'm looking for is if anyone else has experienced this. This makes no sense to me and I don't see how it could possibly crashing... Is this like a bug in Qt or something?

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
David Ludwig
  • 967
  • 2
  • 12
  • 26

1 Answers1

1

Sounds like you have a memory management problem -- either something not initialized properly, or stomping on someone else's memory (buffer overflow). qDebug creates a fairly significant buffer -- which when stomped on won't crash your program, OR for uninitialized values can change their default.

I would check carefully your initialization. Especially check for things that are handled in your constructor that may have been passed with an initializer from your previous class you removed.

e.g.

Foo::Foo(QObject *parent) : QObject(parent)
Scott 'scm6079'
  • 1,517
  • 13
  • 25
  • I've checked all of this in detail before posting. following each line of code finding whats created in what order. Its all correct. Everything is initialized before accessed. – David Ludwig Jul 01 '14 at 14:07