奇怪的Qt行为使我的应用程序崩溃 [英] Weird Qt behavior crashing my application

查看:76
本文介绍了奇怪的Qt行为使我的应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当我在Qt中遇到问题时,通常是由于我不了解某些东西,但是这个问题是不合逻辑的.

Normally when I have a problem in Qt, it is usually due to me not understanding something but this problem is just illogical.

我具有处理热键事件的功能:

I have this function that handle hotkey's event:

bool MainWidget::nativeEvent(const QByteArray& eventType, void* message, long* result)
{
    MSG* msg = reinterpret_cast<MSG*>(message);
    if (msg->message == WM_HOTKEY)
    {
        qDebug() << "It works";   // IF I REMOVE THIS LINE, THE APP CRASHES.
        togglevisibility(false);
    }
}

它运行得很好,但是如果我删除qDebug()行,则该应用程序一开始运行就会崩溃.什么都不会显示.构造函数中的代码可以运行,但是似乎一旦到达该函数,它就会崩溃.

It works perfectly well but if I remove the qDebug() line, then the app crashes as soon as it starts running. Nothing gets displayed. The code in the constructor runs but it seems it crashes as soon as it gets to this function.

在主窗口小部件的构造函数中,我有以下这一行来注册我的热键:

In my constructor of my main widget, I have this line to register my hotkey:

if (!RegisterHotKey(HWND(this->winId()), 1, MOD_CONTROL | MOD_SHIFT | 0x4000, 0x41)) qDebug() << ("Hotkey failed");

添加任何其他行而不是qDebug都没有什么不同.(例如,删除味精).删除行切换可见性"并不会影响该功能.

Adding any other line instead of the qDebug doesn't make a difference. (e.g delete msg). Removing the line 'togglevisility' doesn't make a difference which rules out that function.

如果我将qDebug行移到if语句之前,则不会使应用程序崩溃.似乎以某种方式需要qDebug行,这根本没有任何意义.

If I move the qDebug line before the if statement will NOT crash the application. It would seem that the qDebug line is required somehow which doesn't make any sense at all.

如果任何人都可以理解这一点,请告诉我.我宁愿不将qDebug行留在我的应用程序中.

If anyone can make sense of this, please let me know. I rather not leave qDebug lines in my application.

推荐答案

我了解了如何停止应用程序崩溃并删除qDebug.Qt nativeEvent 事件必须返回布尔值.添加行 return NULL 将停止崩溃.

I found out how to stop the application crashing and removing the qDebug. the Qt nativeEvent event has to return a bool. Adding the line return NULL will stop the crashing.

但是我无法解释为什么qDebug阻止了它的崩溃.

However I cannot explain why qDebug prevented it from crashing before.

这篇关于奇怪的Qt行为使我的应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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