Qt App Crashes If Ran Without a QDebug Message First

家住魔仙堡 提交于 2020-01-03 21:05:13

问题


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?


回答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)


来源:https://stackoverflow.com/questions/24500991/qt-app-crashes-if-ran-without-a-qdebug-message-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!