Qt应用程序崩溃如果没有QDebug消息首先 [英] Qt App Crashes If Ran Without a QDebug Message First

查看:960
本文介绍了Qt应用程序崩溃如果没有QDebug消息首先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天都在处理一个应用程序一段时间,就像几个星期,已经有很大的发展。



我有一个不必要的只是转发对象创建的类。它基本上是一个Window类,创建了一个Widget类。所以我不需要经历那个不必要的Window类来创建Widget类,而是直接在主App类中创建了Widget类。但是现在,如果我运行它,应用程序会像一些递归循环一样崩溃,并且不显示窗口。



我在每行添加了一些QDebug消息看到它在崩溃之前到达哪里,然后运行得很好。这到底是怎么回事?它运行起来就像这样:

  void App :: initialize()
{
qDebug() < 初始化...;

qDebug()<<< 创建小部件;
widget = new Widget();

qDebug()<<< 显示小部件...;
widget-> show();

qDebug()<<< 初始化
}

但是,如果我删除了前两个QDebug消息中的任何一个,它被卡在它的递归式循环。我不知道为什么这样做。我已经检查了项目文件和qmake,运行在调试和发行模式和它的一样。



我不是在寻找一个如何解决的答案这个。我正在寻找的是如果有人经历过这个。这对我来说没有意义,我没有看到它可能如何崩溃...这是一个Qt或某些错误吗?

解决方案

我会仔细检查你的初始化。特别要检查你的构造函数中处理的东西,这些东西可能已经从你先前删除的类中的初始化程序传递过来了。



例如

  Foo :: Foo(QObject * parent) QObject(父)


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?

解决方案

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)

这篇关于Qt应用程序崩溃如果没有QDebug消息首先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆