Qt qDebug not working with QConsoleApplication or QApplication - c++

I currently have a terribly annoying problem while developing programs using Qt and Qt Creator. Whenever I try using qDebug() with a QCoreApplication or QApplication instantiated before using qDebug(), there isn't any output, whether I run the program in Qt Creator or from a normal shell(I'm using Fedora Linux btw). For example, even the following simple code fails:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "TestOutput!" << endl;
}
Does anybody know what to do about this problem?
Thanks in advance,
Marius

For better formatting, I add this new solution, marius still found it himself in this bugzilla.
Edit ~/.config/QtProject/qtlogging.ini and add:
[Rules]
*.debug=true
qt.qpa.input*.debug=false
The last line is to disable spammy debug logging for moved mouse messages.

Docs around this can be found here: http://doc.qt.io/qt-5/qloggingcategory.html#details
It can be configured in many ways. Few useful examples:
by env variable(cmd):
$ export QT_LOGGING_RULES="*.debug=true" ./app
by env variable(export):
$ QT_LOGGING_RULES="*.debug=true"
$ ./app
or in code:
#include <QCoreApplication>
#include <QLoggingCategory>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QLoggingCategory::setFilterRules("*.debug=true");
qDebug() << "Debugging;
a.exit();
}

OK, I found out what the problem was, it was indeed Fedora, but it's the new standard configuration. See here:
https://forum.qt.io/topic/54820/

This one help for me (In user bashrc file):
export QT_LOGGING_DEBUG=1

Related

Why is QPdfDocument not found?

Why is QPdfDocument not found?
During installation I selected Additional Libraries "Qt PDF" and "Qt WebEngine". Then I wrote this code in CMake:
find_package(Qt6 REQUIRED COMPONENTS Pdf)
target_link_libraries(mytarget Qt6::Pdf)
Then I got the message:
"Found package configuration file: C:/Qt/6.3.1/mingw_64/lib/cmake/Qt6/Qt6Config.cmake but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT FOUND. Reason given by package: Failed to find Qt component "Pdf". Expected Config file at "C:/Qt/6.3.1/mingw_64/lib/cmake/Qt6Pdf/Qt6PdfConfig.cmake" does NOT exist"
#include <QApplication>
#include <QPdfDocument> //not found
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Dont know the qt version. Community Edition? Maybe this helps:
QtPDF Build Instructions

QSystemTrayIcon not showing after using windeployqt tool [duplicate]

This question already has answers here:
QSystemTrayIcon and Windows8
(2 answers)
Closed 3 years ago.
Note: Yes, this question has been asked and answered previously, but the duplicate's answer is incomplete. Please see my solution if you are stuck on this.
Using Qt 5.13.0 MSVC2017 64-bit and Windows 10, I'm experiencing some strange behavior from QSystemTrayIcon. When running in Debug or Release from QtCreator on a fresh build, there are no issues and the icon displays exactly how I would expect it to. However, after using the windeployqt.exe tool, the icon stops showing up.
This happens both when I run it from QtCreator after windeployqt.exe and from the installation directory via Qt Installer Framework. If I delete the build directory, clean, and rebuild, the problem goes away, but obviously this is an issue for deployment.
Command:
windeployqt.exe <RELEASE_DIR>
(also tried specifying the executable directly)
MainWindow constructor:
AltheaWindow::AltheaWindow(MacroListModel &macroListModel, Config *config, const QString &configPath, QWidget *parent)
: QMainWindow(parent),
ui(new Ui::AltheaWindow),
macros(macroListModel),
config(config),
trayIcon(QIcon(IconPath), this),
shortcutNew(ShortcutPtr(new QShortcut(NewMacro, this))),
shortcutSave(ShortcutPtr(new QShortcut(SaveMacro, this))) {
qDebug() << "AltheaWindow";
ui->setupUi(this);
ui->sidebar->createSettingsDialog(config, configPath);
initConnections();
QFile f(IconPath);
bool exists = f.exists();
qDebug() << "exists = " << exists; // "exists = true"
trayIcon.show();
ui->sidebar->setMacros(&macroListModel);
if ((*(*config)[AltheaConfig::StartMinimized]).toBool()) showMinimized();
}
Regardless of whether the icon is shown or not, exists is always true, so it doesn't seem to be an issue of resolving the resource. All other resources in the application work fine as well.
Found the solution, copy imageformats to the plugins directory.
Solution: https://stackoverflow.com/a/20594583/2472874
Additional note:
For anyone experiencing this issue, I found that I also needed to have the imageformats plugin on the Library Paths before the application object is initialized.
#define PLUGINS "plugins"
void preInit(char *argv[]);
int main(int argc, char *argv[]) {
#ifndef _DEBUG
preInit(argv);
#endif
Althea app(argc, argv);
AltheaWindow w(app.getMacros(), &app.getConfig(), app.getAppData().absoluteFilePath(Althea::ConfigFileName));
w.show();
return app.exec();
}
void preInit(char *argv[]) {
QDir releaseDir(QFileInfo(argv[0]).dir());
QCoreApplication::addLibraryPath(releaseDir.absoluteFilePath(PLUGINS));
}

QT Console Application in Lubuntu

I'm trying to write a console app in Qt under Lubuntu.
But when I'm trying to run something, i.e.:
#include <QCoreApplication>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cout << " hello world";
return a.exec();
}
it fails, saying :
"Cannot change to working directory home/myusername/myproject: no such
a file or directory".
But this directory exists, there's even the build file in it, marked as executable. But when I trying to run it from the terminal, the response is: myproject-console is not a command.
What happened to "Hello, World!" app? Is there any way to solve it?
It appears that your application tries to look for a relative path home/myusername/myproject and not for the absolute path /home/myusername/myproject. Have you checked the path contained in argv?

Compiler can't find ui_xyz.h file

I've install Netbeans 7.2 and Qt 5 on Windows7. Everything compiles fine.
But recently when I create a Qt form and try to use it in this way:
New Project > C/C++ Qt Application > Finish
Right click on new Qt project > New > Qt Form > Finish
After saving ui file in Designer
This error appears:
newForm.h:11:24: fatal error: ui_newForm.h: No such file or directory
The content of main.cpp is :
#include <QGuiApplication>
#include "newForm.h"
int main(int argc, char *argv[])
{
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QGuiApplication app(argc, argv);
// create and show your widgets here
return app.exec();
}
I tried to manually create ui_xwz.h file and add it to my project. But I want it work automatically as same as before. How can I solve it?
I have a ridiculous solution, Maybe we should report it as a bug to Netbeans or Qt.
Go and active QtSVG and QtXml modules of your project and rebuild it. I tested this way and the problem vanished.

QLibraryInfo doesn't seem to load qt.conf

I jsut installed Qt 4.7.2 and I'm trying to use the QLibraryInfo class. My problem is that QLibraryInfo::location(QLibraryInfo::PrefixPath) always returns C:\work3\qt-4.7-vs2010-x86 which doesn't exist on my generation machine (should be C:\Qt\qt-4.7.2).
According to the documentation I tried to create a qt.conf file alongside my program, but the problem still remains. Here's its content:
[Paths]
Prefix=C:/Qt/qt-4.7.2/
For now I used a symlink to bypass the issue, but I'd like to know if there's a proper solution.
Thanks.
EDIT
Here's the program using the QLibraryInfo:
int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv); //< added after Piotr's suggestion
QFile outf("qtdirs.out");
if (!outf.open(QIODevice::WriteOnly|QIODevice::Truncate|QIODevice::Text))
return 1;
QTextStream out(&outf);
out << QLibraryInfo::location(QLibraryInfo::PrefixPath) << '\n';
out << QLibraryInfo::location(QLibraryInfo::HeadersPath) << '\n';
...
}
A QCoreApplication must be created because that is how the QLibraryInfo is able to determine the application directory (QCoreApplication::applicationDirPath()) from which to load the qt.conf file. Alternatively, the qt.conf can be built into the application as a resource with the path ":/qt/etc/qt.conf".