qDebug() is not working anymore in QT-Creator (Installed from QT-Installer from QT.io, OS: Manjaro Linux
-
I've Googled for hours but I was not able to get the qDebug() function to work anymore (https://doc.qt.io/qt-6/qdebug.html). This function is very helpful for debugging and finding errors. The suggestion I've found was to use the c-function iostream, this one isn't working too. Here my code:
The *.pro File:
QT += core widgets multimedia CONFIG += c++17 CONFIG += console # 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 \ mpegswissknife.cpp HEADERS += \ mpegswissknife.h FORMS += \ mpegswissknife.ui TRANSLATIONS += \ MPEG-SwissKnife_de_CH.ts CONFIG += lrelease CONFIG += embed_translations # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target DISTFILES += ```$ The *.h file:#ifndef MPEGSWISSKNIFE_H
#define MPEGSWISSKNIFE_H#include <QMainWindow>
#include <QDateTime>QT_BEGIN_NAMESPACE
namespace Ui {
class MPEGSwissKnife;
}
QT_END_NAMESPACEclass MPEGSwissKnife : public QMainWindow
{
Q_OBJECTpublic:
explicit MPEGSwissKnife(QWidget *parent = nullptr);
~MPEGSwissKnife() override;private slots:
void on_selectSourceBtn_clicked();void on_selectTargetBtn_clicked();private:
Ui::MPEGSwissKnife *ui;
QString inputFileName, targetFileName;
qint64 movieDuration;
QTime movieTime;
};
#endif // MPEGSWISSKNIFE_HThe main.cpp File:#include "mpegswissknife.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>int main(int argc, char *argv[])
{
QApplication a(argc, argv);QTranslator translator; const QStringList uiLanguages = QLocale::system().uiLanguages(); for (const QString &locale : uiLanguages) { const QString baseName = "MPEG-SwissKnife_" + QLocale(locale).name(); if (translator.load(":/i18n/" + baseName)) { a.installTranslator(&translator); break; } } MPEGSwissKnife w; w.show(); return QApplication::exec();}
``
The *.cpp file:
`#include "mpegswissknife.h" #include "ui_mpegswissknife.h" #include <QFileDialog> #include <QCoreApplication> #include <QDebug> MPEGSwissKnife::MPEGSwissKnife(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MPEGSwissKnife) { ui->setupUi(this); } MPEGSwissKnife::~MPEGSwissKnife() { delete ui; } //ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 void MPEGSwissKnife::on_selectSourceBtn_clicked() { inputFileName = QFileDialog::getOpenFileName(this, tr("Open Source Video File"), "/home", tr("MP4-Videos (*.mp4 *.MP4")); ui->sourceFileLabel->setText(inputFileName); qDebug() << inputFileName; movieTime.setHMS(0,0,0,0); QString cmd = "ffmpeg"; QStringList args; args << "-v error" << "-show_entries" << "format=duration" << "-of default=noprint_wrappers=1:nokey=1"; qDebug() << "Hallo: " << cmd << " - " << args; //ui->fileLengthlabel->setText(movieTime.toString("hh:mm:ss.z")); ui->fileLengthlabel->setText(QString::number(movieDuration)); } void MPEGSwissKnife::on_selectTargetBtn_clicked() { targetFileName = QFileDialog::getSaveFileName(this, tr("Save modified Video at"), "/home/hk/Videos/untitled.mp4", tr("MP4-Videos (*.mp4 *.MP4")); ui->targetFileLabel->setText(targetFileName); }The *.ui File:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MPEGSwissKnife</class> <widget class="QMainWindow" name="MPEGSwissKnife"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>900</width> <height>340</height> </rect> </property> <property name="minimumSize"> <size> <width>900</width> <height>340</height> </size> </property> <property name="maximumSize"> <size> <width>900</width> <height>340</height> </size> </property> <property name="windowTitle"> <string>MPEGSwissKnife</string> </property> <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QTabWidget" name="concatenateWidget"> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="concatenate"> <attribute name="title"> <string>Split</string> </attribute> <layout class="QGridLayout" name="gridLayout_2"> <item row="0" column="0"> <layout class="QGridLayout" name="gridLayout"> <item row="2" column="1"> <widget class="QLabel" name="fileLengthlabel"> <property name="text"> <string/> </property> </widget> </item> <item row="0" column="0"> <widget class="QLabel" name="label"> <property name="maximumSize"> <size> <width>100</width> <height>16777215</height> </size> </property> <property name="text"> <string>Source File:</string> </property> </widget> </item> <item row="2" column="0"> <widget class="QLabel" name="label_3"> <property name="text"> <string>File Length:</string> </property> </widget> </item> <item row="0" column="1"> <widget class="QPushButton" name="selectSourceBtn"> <property name="maximumSize"> <size> <width>100</width> <height>16777215</height> </size> </property> <property name="text"> <string>Select Source</string> </property> </widget> </item> <item row="1" column="0"> <widget class="QLabel" name="label_2"> <property name="text"> <string>Target File:</string> </property> </widget> </item> <item row="1" column="1"> <widget class="QPushButton" name="selectTargetBtn"> <property name="text"> <string>Select Target</string> </property> </widget> </item> <item row="2" column="2" colspan="2"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QLabel" name="label_4"> <property name="maximumSize"> <size> <width>75</width> <height>16777215</height> </size> </property> <property name="text"> <string>Start Time:</string> </property> </widget> </item> <item> <widget class="QTimeEdit" name="startTimeEdit"> <property name="displayFormat"> <string>HH:mm:ss.z</string> </property> </widget> </item> <item> <widget class="QComboBox" name="timeDurationSelector"/> </item> <item> <widget class="QTimeEdit" name="timeEdit"> <property name="displayFormat"> <string>HH:mm:ss.z</string> </property> </widget> </item> </layout> </item> <item row="0" column="2" colspan="2"> <widget class="QLabel" name="sourceFileLabel"> <property name="text"> <string/> </property> </widget> </item> <item row="1" column="2" colspan="2"> <widget class="QLabel" name="targetFileLabel"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="text"> <string/> </property> </widget> </item> </layout> </item> <item row="1" column="0"> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Orientation::Vertical</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>20</width> <height>40</height> </size> </property> </spacer> </item> </layout> </widget> <widget class="QWidget" name="split"> <attribute name="title"> <string>Concatenate</string> </attribute> </widget> </widget> </item> </layout> </item> <item> <widget class="QTextEdit" name="ffmpegOutput"/> </item> </layout> </widget> <widget class="QStatusBar" name="statusbar"/> </widget> <resources/> <connections/> </ui> -
I've Googled for hours but I was not able to get the qDebug() function to work anymore (https://doc.qt.io/qt-6/qdebug.html). This function is very helpful for debugging and finding errors. The suggestion I've found was to use the c-function iostream, this one isn't working too. Here my code:
The *.pro File:
QT += core widgets multimedia CONFIG += c++17 CONFIG += console # 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 \ mpegswissknife.cpp HEADERS += \ mpegswissknife.h FORMS += \ mpegswissknife.ui TRANSLATIONS += \ MPEG-SwissKnife_de_CH.ts CONFIG += lrelease CONFIG += embed_translations # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target DISTFILES += ```$ The *.h file:#ifndef MPEGSWISSKNIFE_H
#define MPEGSWISSKNIFE_H#include <QMainWindow>
#include <QDateTime>QT_BEGIN_NAMESPACE
namespace Ui {
class MPEGSwissKnife;
}
QT_END_NAMESPACEclass MPEGSwissKnife : public QMainWindow
{
Q_OBJECTpublic:
explicit MPEGSwissKnife(QWidget *parent = nullptr);
~MPEGSwissKnife() override;private slots:
void on_selectSourceBtn_clicked();void on_selectTargetBtn_clicked();private:
Ui::MPEGSwissKnife *ui;
QString inputFileName, targetFileName;
qint64 movieDuration;
QTime movieTime;
};
#endif // MPEGSWISSKNIFE_HThe main.cpp File:#include "mpegswissknife.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>int main(int argc, char *argv[])
{
QApplication a(argc, argv);QTranslator translator; const QStringList uiLanguages = QLocale::system().uiLanguages(); for (const QString &locale : uiLanguages) { const QString baseName = "MPEG-SwissKnife_" + QLocale(locale).name(); if (translator.load(":/i18n/" + baseName)) { a.installTranslator(&translator); break; } } MPEGSwissKnife w; w.show(); return QApplication::exec();}
``
The *.cpp file:
`#include "mpegswissknife.h" #include "ui_mpegswissknife.h" #include <QFileDialog> #include <QCoreApplication> #include <QDebug> MPEGSwissKnife::MPEGSwissKnife(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MPEGSwissKnife) { ui->setupUi(this); } MPEGSwissKnife::~MPEGSwissKnife() { delete ui; } //ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 void MPEGSwissKnife::on_selectSourceBtn_clicked() { inputFileName = QFileDialog::getOpenFileName(this, tr("Open Source Video File"), "/home", tr("MP4-Videos (*.mp4 *.MP4")); ui->sourceFileLabel->setText(inputFileName); qDebug() << inputFileName; movieTime.setHMS(0,0,0,0); QString cmd = "ffmpeg"; QStringList args; args << "-v error" << "-show_entries" << "format=duration" << "-of default=noprint_wrappers=1:nokey=1"; qDebug() << "Hallo: " << cmd << " - " << args; //ui->fileLengthlabel->setText(movieTime.toString("hh:mm:ss.z")); ui->fileLengthlabel->setText(QString::number(movieDuration)); } void MPEGSwissKnife::on_selectTargetBtn_clicked() { targetFileName = QFileDialog::getSaveFileName(this, tr("Save modified Video at"), "/home/hk/Videos/untitled.mp4", tr("MP4-Videos (*.mp4 *.MP4")); ui->targetFileLabel->setText(targetFileName); }The *.ui File:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MPEGSwissKnife</class> <widget class="QMainWindow" name="MPEGSwissKnife"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>900</width> <height>340</height> </rect> </property> <property name="minimumSize"> <size> <width>900</width> <height>340</height> </size> </property> <property name="maximumSize"> <size> <width>900</width> <height>340</height> </size> </property> <property name="windowTitle"> <string>MPEGSwissKnife</string> </property> <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QTabWidget" name="concatenateWidget"> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="concatenate"> <attribute name="title"> <string>Split</string> </attribute> <layout class="QGridLayout" name="gridLayout_2"> <item row="0" column="0"> <layout class="QGridLayout" name="gridLayout"> <item row="2" column="1"> <widget class="QLabel" name="fileLengthlabel"> <property name="text"> <string/> </property> </widget> </item> <item row="0" column="0"> <widget class="QLabel" name="label"> <property name="maximumSize"> <size> <width>100</width> <height>16777215</height> </size> </property> <property name="text"> <string>Source File:</string> </property> </widget> </item> <item row="2" column="0"> <widget class="QLabel" name="label_3"> <property name="text"> <string>File Length:</string> </property> </widget> </item> <item row="0" column="1"> <widget class="QPushButton" name="selectSourceBtn"> <property name="maximumSize"> <size> <width>100</width> <height>16777215</height> </size> </property> <property name="text"> <string>Select Source</string> </property> </widget> </item> <item row="1" column="0"> <widget class="QLabel" name="label_2"> <property name="text"> <string>Target File:</string> </property> </widget> </item> <item row="1" column="1"> <widget class="QPushButton" name="selectTargetBtn"> <property name="text"> <string>Select Target</string> </property> </widget> </item> <item row="2" column="2" colspan="2"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QLabel" name="label_4"> <property name="maximumSize"> <size> <width>75</width> <height>16777215</height> </size> </property> <property name="text"> <string>Start Time:</string> </property> </widget> </item> <item> <widget class="QTimeEdit" name="startTimeEdit"> <property name="displayFormat"> <string>HH:mm:ss.z</string> </property> </widget> </item> <item> <widget class="QComboBox" name="timeDurationSelector"/> </item> <item> <widget class="QTimeEdit" name="timeEdit"> <property name="displayFormat"> <string>HH:mm:ss.z</string> </property> </widget> </item> </layout> </item> <item row="0" column="2" colspan="2"> <widget class="QLabel" name="sourceFileLabel"> <property name="text"> <string/> </property> </widget> </item> <item row="1" column="2" colspan="2"> <widget class="QLabel" name="targetFileLabel"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="text"> <string/> </property> </widget> </item> </layout> </item> <item row="1" column="0"> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Orientation::Vertical</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>20</width> <height>40</height> </size> </property> </spacer> </item> </layout> </widget> <widget class="QWidget" name="split"> <attribute name="title"> <string>Concatenate</string> </attribute> </widget> </widget> </item> </layout> </item> <item> <widget class="QTextEdit" name="ffmpegOutput"/> </item> </layout> </widget> <widget class="QStatusBar" name="statusbar"/> </widget> <resources/> <connections/> </ui>@HansKottmann
You seem to have a UI application but your configuration isCONFIG += console. Is that an issue?not able to get the qDebug() function to work anymore
So since when/what does it not work "anymore"?
-
I tried all you've suggested and what I found in the Internet. Without success, I assume that this is a severe bug in QtCreator, at least in the Linux version, I did not try any other platforms like Windows, etc. I use now a QTextEdit to output all debug messages I need, so my problem is creatively solved and I can go ahead.
-
Now I have another problem, I can't get QProcess to work, it fails always with unknown error. The program I'm writing should do at the moment to call FFMPEG (ffprobe) to get the duration of the video I've selected in the gui, here the debug output. The commands for both videos are working fine when I copy them into a Linux terminal. Here the debug output:
/home/hk/Videos/gay-thai.mp4 /usr/bin/ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "/home/hk/Videos/gay-thai.mp4" Unbekannter Fehler Hallo 0 /home/hk/Videos/Moderne Frauen sind überteuert liefern zu wenig und Männer haben.mp4 /usr/bin/ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "/home/hk/Videos/Moderne Frauen sind überteuert liefern zu wenig und Männer haben.mp4" Unbekannter Fehler Hallo 0As suggested in the net, I've set the working directory in QT: QDir::setCurrent(QDir::rootPath());
-
Now I have another problem, I can't get QProcess to work, it fails always with unknown error. The program I'm writing should do at the moment to call FFMPEG (ffprobe) to get the duration of the video I've selected in the gui, here the debug output. The commands for both videos are working fine when I copy them into a Linux terminal. Here the debug output:
/home/hk/Videos/gay-thai.mp4 /usr/bin/ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "/home/hk/Videos/gay-thai.mp4" Unbekannter Fehler Hallo 0 /home/hk/Videos/Moderne Frauen sind überteuert liefern zu wenig und Männer haben.mp4 /usr/bin/ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "/home/hk/Videos/Moderne Frauen sind überteuert liefern zu wenig und Männer haben.mp4" Unbekannter Fehler Hallo 0As suggested in the net, I've set the working directory in QT: QDir::setCurrent(QDir::rootPath());
@HansKottmann
May depend on how you useQProcessand where you get the error message from. -
Here my code, I would be happy to learn from you
Declaration of QProcess in the header file:
QProcess *procTime = new QProcess(this)Code in the *.cpp file
QString cmd = "/usr/bin/ffprobe"; QStringList args; args << "-v error" << "-show_entries" << "format=duration" << "-of default=noprint_wrappers=1:nokey=1" << inputFileName.trimmed().prepend("\"").append("\""); connect(procTime, SIGNAL(readyRead()), this, SLOT(collectTimeData())); procTime->start(cmd, args); sendDebug(procTime->program() + " " + procTime->arguments().join(" ")); sendDebug(procTime->errorString()); procTime->waitForStarted();sendDebug() is the function that sends the debug messages to a QTextEdit window as I was not able to get QDebug to work.
My platform is Manjaro Linux, QtCreator was installed with the installer from qt.io -
Here my code, I would be happy to learn from you
Declaration of QProcess in the header file:
QProcess *procTime = new QProcess(this)Code in the *.cpp file
QString cmd = "/usr/bin/ffprobe"; QStringList args; args << "-v error" << "-show_entries" << "format=duration" << "-of default=noprint_wrappers=1:nokey=1" << inputFileName.trimmed().prepend("\"").append("\""); connect(procTime, SIGNAL(readyRead()), this, SLOT(collectTimeData())); procTime->start(cmd, args); sendDebug(procTime->program() + " " + procTime->arguments().join(" ")); sendDebug(procTime->errorString()); procTime->waitForStarted();sendDebug() is the function that sends the debug messages to a QTextEdit window as I was not able to get QDebug to work.
My platform is Manjaro Linux, QtCreator was installed with the installer from qt.io@HansKottmann said in qDebug() is not working anymore in QT-Creator (Installed from QT-Installer from QT.io, OS: Manjaro Linux:
procTime->start(cmd, args); sendDebug(procTime->program() + " " + procTime->arguments().join(" ")); sendDebug(procTime->errorString()); procTime->waitForStarted();You are printing
errorString()afterstart()but before evenwaitForStarted(). I would suggest yourUnbekannter Fehleris because there is no error at this point. You have not shown any error occurs.I do not know about your argument quoting. Is
-v errorreally supposed to be a single argument, it isn't if you pasted it on a command line? You are quoting the filepath? I am not sure all this quoting is correct/desired as arguments directly toffprobe, you might need tosh -c "..."it if you are not sure. But this comes after you sort out your error tester/printing. -
Here my code, I would be happy to learn from you
Declaration of QProcess in the header file:
QProcess *procTime = new QProcess(this)Code in the *.cpp file
QString cmd = "/usr/bin/ffprobe"; QStringList args; args << "-v error" << "-show_entries" << "format=duration" << "-of default=noprint_wrappers=1:nokey=1" << inputFileName.trimmed().prepend("\"").append("\""); connect(procTime, SIGNAL(readyRead()), this, SLOT(collectTimeData())); procTime->start(cmd, args); sendDebug(procTime->program() + " " + procTime->arguments().join(" ")); sendDebug(procTime->errorString()); procTime->waitForStarted();sendDebug() is the function that sends the debug messages to a QTextEdit window as I was not able to get QDebug to work.
My platform is Manjaro Linux, QtCreator was installed with the installer from qt.io@HansKottmann To add to @JonB you should connect a slot to https://doc.qt.io/qt-6/qprocess.html#errorOccurred and print the error there.
-
@HansKottmann
As @jsulm has written. And/or, bothwaitForStarted()andwaitForFinished()return abool, only if they returnfalsecan you then get a meaningfulerror()/errorString()(can do that without signal/slot).As I wrote before, I am dubious about your argument passing. I would expect you to use/need something more like:
args << "-v" << "error" << "-show_entries" << "format=duration" << "-of" << "default=noprint_wrappers=1:nokey=1" << inputFileName.trimmed();based on what you say works from the command line.
-
I've changed the args stringlist as you proposed and I still get Unknown Error. I assume as qDebug is not working too, that QT isn't working with Manjaro. It's a mess as I relayed for year in QT, but it got obviously useless.
-
I switched to openSuSE tumbleweed. QDebug works but the unknown error remains
-
The only thing I've changed is the args QStringList, it looks now exactly like yours, the only difference are the quotation marks at the beginning and the end of the file path string because filenames can have white spaces:
args << "-v" << "error" << "-show_entries" << "format=duration" << "-of" << "default=noprint_wrappers=1:nokey=1" << inputFileName.trimmed().prepend("\"").append("\"");The problem with QCommand is not yet solve, I will try first very simple commands first without args, then with one, then two... I think this is the only way to debug this.
-
The only thing I've changed is the args QStringList, it looks now exactly like yours, the only difference are the quotation marks at the beginning and the end of the file path string because filenames can have white spaces:
args << "-v" << "error" << "-show_entries" << "format=duration" << "-of" << "default=noprint_wrappers=1:nokey=1" << inputFileName.trimmed().prepend("\"").append("\"");The problem with QCommand is not yet solve, I will try first very simple commands first without args, then with one, then two... I think this is the only way to debug this.
@HansKottmann said in qDebug() is not working anymore in QT-Creator (Installed from QT-Installer from QT.io, OS: Manjaro Linux:
The only thing I've changed is the args QStringList, it looks now exactly like yours, the only difference are the quotation marks at the beginning and the end of the file path string because filenames can have white spaces:
I already explained earlier that you are calling
errorString()too early. So did @jsulm . And what to do about it. YourUnknown Errorcurrently does not indicate anything has gone wrong. You need to change your code.Your understanding of whitespace as it appears when you type a command into a shell versus how to pass arguments to spawned processes is not right. The arglist should be as a wrote and not have quotes. Or send the whole command line to
bash -c.