我刚刚开始使用 Qt Creator V4.13 和 Qt V5.15.1 学习 Qt,当我使用 qDebug()、qInfo()、qWarning() 和 qCritical() 时,它不会在应用程序输出中显示任何内容。
[编辑] 我检查了“在终端中运行”,然后清理并重建项目,它现在使用“qtcreator_process_sub”运行,并带有 qDebug 所需的输出。
。轮廓
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
TRANSLATIONS += \
ToDo_ar_EG.ts
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
MainWindow.h 文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void addTask();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
MainWindow.cpp 文件
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QtWidgets/QPushButton"
#include "QDebug"
#include <iostream>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->addTaskButton, &QPushButton::clicked, this, &MainWindow::addTask);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::addTask()
{
qDebug()<<"Debug button";
qInfo()<<"Information output";
qWarning()<<"Warning output";
qCritical()<<"Critical output";
}
我花了两天时间在 Google 上搜索,但所有答案都是关于未定义 QT_NO_DEBUG_OUTPUT 但它已定义。我尝试过的:包括“QtDebug”而不是“qDebug”创建带有内容的 qtlogging.ini:-
[Rules]
*.debug=true
每次编辑后都尝试了一个干净的构建(干净和重建项目)
眼镜:
Arch Linux(系统是最新的我刚刚更新了它)
V4.13 和 Qt V5.15.1
CMake V3.18.2
制作V4.3
QMake V3.1