You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Ubuntu 17.10/Fedora后qDebug()无控制台输出,如何重新启用?

Hey there! I've run into this exact issue before after upgrading my Ubuntu system, so I know how frustrating it can be when qDebug() goes silent mid-debugging. Let's break down the most common causes and fixes to get your debug output back:

Fixes for qDebug() Not Printing After Ubuntu 17.10/Fedora Upgrade

1. Override Qt's Default Logging Rules

Newer Qt versions shipped with these OS updates often use stricter default logging filters that suppress qDebug() output. You can quickly test this by setting an environment variable before running your app:

export QT_LOGGING_RULES="*.debug=true"
./your-qt-application

If this works, make it permanent by adding that export line to your ~/.bashrc (for Bash) or ~/.zshrc (for Zsh). For GUI apps launched from the desktop, you can add the variable to your app's .desktop file under the Exec line:

Exec=env QT_LOGGING_RULES="*.debug=true" /path/to/your/app

Alternatively, set the rules directly in your code early on (before any qDebug() calls):

#include <QLoggingCategory>

int main(int argc, char *argv[]) {
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QLoggingCategory::setFilterRules("*.debug=true"); // Enable all debug messages
    QApplication app(argc, argv);
    // ... rest of your code
}

2. Verify Build Configuration Isn't Disabling Debug Output

If you're building in Release mode, Qt automatically disables qDebug() unless you explicitly enable it. Open your project's .pro file and:

  • Ensure there's no DEFINES += QT_NO_DEBUG_OUTPUT line (this completely turns off qDebug()).
  • Add DEFINES += QT_MESSAGELOGCONTEXT if you want to include file/line numbers in debug output (optional but super helpful for tracing issues).

After making changes, re-run qmake and rebuild your project.

3. Run Your App Directly in the Terminal

Desktop environments like GNOME on Ubuntu/Fedora often redirect stdout/stderr of GUI apps away from the terminal. Instead of launching from the desktop menu, open a terminal, navigate to your app's directory, and run it directly. This ensures you'll see any output being sent to the console.

4. Check System-Wide Qt Logging Settings

Some OS updates modify the global Qt logging config file. Check /etc/xdg/QtProject/qtlogging.ini for lines like:

[Rules]
*.debug=false

If you find this, either delete the line or change false to true. You'll need sudo privileges to edit the file:

sudo nano /etc/xdg/QtProject/qtlogging.ini

Save the changes and restart your app to apply them.

Bonus: Isolate the Issue with a Minimal Test App

If none of the above works, create a tiny test app to rule out project-specific issues:

#include <QApplication>
#include <QDebug>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    qDebug() << "Hello from qDebug! Is this working?";
    return app.exec();
}

Build and run this. If it prints, the problem is in your main project's configuration; if not, it's a system-wide Qt setting that needs adjustment.


内容的提问来源于stack exchange,提问作者Yusef Maali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:33:56