I'm using Qt 5.6 on Fedora 23 and I noticed that console.log() and console.debug() don't write anything to console. My example code:
import QtQuick 2.6
import QtQuick.Window 2.2
Window {
visible: true
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
Component.onCompleted: {
console.warn("warn completed")
console.log("log completed")
console.error("error completed")
console.debug("debug completed")
console.exception("exception completed")
console.info("info completed")
}
}
}
prints to console:
QML debugging is enabled. Only use this in a safe environment.
qml: warn completed
qml: error completed
qml: exception completed
onCompleted (qrc:/main.qml:16)
qml: info completed
so warn, error, exception, and info work fine. What am I doing wrong?
Edit #1:
Project is freshly created, all my sources:
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
project.pro
TEMPLATE = app
QT += qml quick
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
Edit #2:
Compile Output from Qt Creator shows that there are no QT_NO_DEBUG_OUTPUT, QT_NO_INFO_OUTPUT, or QT_NO_WARNING_OUTPUT:
14:43:36: Running steps for project project...
14:43:36: Configuration unchanged, skipping qmake step.
14:43:36: Starting: "/usr/bin/make"
g++ -c -pipe -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../project -I. -I../../Qt5.6.0/5.6/gcc_64/include -I../../Qt5.6.0/5.6/gcc_64/include/QtQuick -I../../Qt5.6.0/5.6/gcc_64/include/QtGui -I../../Qt5.6.0/5.6/gcc_64/include/QtQml -I../../Qt5.6.0/5.6/gcc_64/include/QtNetwork -I../../Qt5.6.0/5.6/gcc_64/include/QtCore -I. -I../../Qt5.6.0/5.6/gcc_64/mkspecs/linux-g++ -o main.o ../project/main.cpp
/home/krzys/Qt5.6.0/5.6/gcc_64/bin/rcc -name qml ../project/qml.qrc -o qrc_qml.cpp
g++ -c -pipe -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../project -I. -I../../Qt5.6.0/5.6/gcc_64/include -I../../Qt5.6.0/5.6/gcc_64/include/QtQuick -I../../Qt5.6.0/5.6/gcc_64/include/QtGui -I../../Qt5.6.0/5.6/gcc_64/include/QtQml -I../../Qt5.6.0/5.6/gcc_64/include/QtNetwork -I../../Qt5.6.0/5.6/gcc_64/include/QtCore -I. -I../../Qt5.6.0/5.6/gcc_64/mkspecs/linux-g++ -o qrc_qml.o qrc_qml.cpp
g++ -Wl,-z,origin -Wl,-rpath,\$ORIGIN -Wl,-rpath,/home/krzys/Qt5.6.0/5.6/gcc_64/lib -o project main.o qrc_qml.o -L/home/krzys/Qt5.6.0/5.6/gcc_64/lib -lQt5Quick -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -lGL -lpthread
14:43:37: The process "/usr/bin/make" exited normally.
14:43:37: Elapsed time: 00:01.
Fedora 22 and later disables Qt debug output by default [1]. You can enable Qt debug output by modifying the system-wide /etc/xdg/QtProject/qtlogging.ini or by creating a user-specific configuration file ~/.config/QtProject/qtlogging.ini for example with the following contents:
[Rules]
*.debug=true
https://bugzilla.redhat.com/show_bug.cgi?id=1227295
I found a more convenient solution by adding one of the two - depending
on if you use Qt Quick 1 or 2 to the pro file (rebuild and run QMake again)
according to https://doc.qt.io/qt-5/qtquick-debugging.html:
Qt Quick 1: CONFIG+=declarative_debug
Qt Quick 2: CONFIG+=qml_debug
To put it in your code it would look like:
project.pro
TEMPLATE = app
QT += qml quick
CONFIG += c++11 qml_debug #or CONFIG+=declarative_debug for QtQuick 1
SOURCES += main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
Now it might look like this:
Instead of enabling Debug logging system wide like jpnurmi suggests in the accepted answer. You can simply set a system variable to get the debug messages to show up in the console. Qt Wiki about Logging Rules
To set it for one single execution of your app or qmlscene/qhot qml-preview. If you are starting them from the commandline:
$ QT_LOGGING_RULES="*.debug=true; qt.*.debug=false" your_executable
$ QT_LOGGING_RULES="*.debug=true; qt.*.debug=false" qmlscene/qhot main.qml
Or to set it for this session only (will be unset after reboot). And should be respected even if you launch/test from QtCreator or other IDE:
$ export QT_LOGGING_RULES="*.debug=true; qt.*.debug=false"
And then just start/test your executable or qmlscene/qhot normally
Why is this better?
Setting the logging rules systemwide will mean all Qt apps you run will write debug messages to their logfiles. I discovered a few log files that were gigabytes in size because the apps were accumulating a huge amount debug messages in their logs during normal usage.
Related
Why I got an error:
I use Qt Creator. Version Qt 5.9.7 for Desktop
Output::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
23:02:13: Uruchamianie "/usr/bin/make"
g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../Kurs_STL_cpp0x -I. -I../../anaconda3/mkspecs/linux-g++ -o main.o ../Kurs_STL_cpp0x/main.cpp
../Kurs_STL_cpp0x/main.cpp:4:10: fatal error: Debug: No such file or directory
#include <Debug>
^~~~~~~
compilation terminated.
Makefile:627: recipe for target 'main.o' failed
make: *** [main.o] Error 1
23:02:13: Proces "/usr/bin/make" zakończył się kodem wyjściowym 2.
Błąd budowania / instalowania projektu Kurs_STL_cpp0x (zestaw narzędzi: Desktop)
Podczas wykonywania kroku "Make"
23:02:13: Czas trwania: 00:00.
When you select a non-Qt project, the generated *.pro file is configured to disable Qt (and you will not be able to include Qt files).
In *.pro file, remove the line CONFIG -= qt to enable Qt.
After that, you may need to include the different Qt modules (widgets, quick, etc.) by adding them to the env variable QT (the module core and gui should be enabled by default).
For example, to use the Qt Widgets and Qt Quick, you have to add QT += widgets quick
You can also disable useless modules by adding a line like QT -= gui
I am trying to install and use QT framework on my Windows 7 Professional edition 32 bits machine. I downloaded whole pack (800+ mb) of QT and run installer.
AFter that I added to my system PATH two lines:
J:\Qt\Qt5.0.1\5.0.1\mingw47_32\bin;
J:\Qt\Qt5.0.1\Tools\MinGW\bin
After that I created empty project in QT with simple program, that QT created for me by itself. Applications -> QT gui application, "Use as default project location", Next, Next, Next.
And here is the code, that was created:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
After that I hit Run button on beneath get following error:
19:23:09: Running steps for project qldt...
19:23:09: Configuration unchanged, skipping qmake step.
19:23:09: Starting: "J:\Qt\Qt5.0.1\Tools\MinGW\bin\mingw32-make.exe"
J:/Qt/Qt5.0.1/Tools/MinGW/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'J:/Users/shidant2/Desktop/workspace/qldt/qldt-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug'
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT_OPENGL_ES_2_ANGLE -DQT_NEEDS_QMAIN -I..\qldt -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include" -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtWidgets" -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtGui" -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtCore" -I"debug" -I"." -I"." -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\mkspecs\win32-g++" -o debug\main.o ..\qldt\main.cpp
Makefile.Debug:357: recipe for target 'debug/main.o' failed
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make[1]: Leaving directory 'J:/Users/shidant2/Desktop/workspace/qldt/qldt-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug'
makefile:34: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2
19:23:30: The process "J:\Qt\Qt5.0.1\Tools\MinGW\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project qldt (kit: Desktop Qt 5.0.1 MinGW 32bit)
When executing step 'Make'
As I understand, there no problem with the code, but with compiler.
I tried to look for solution, but did not find anything useful..
I guess such serious framework as QT has not to live with such problem, espicially when it impacts the beginner experience.
So, please, lets solve it here and now )
I found something interesting.
I tried to build everyhing withut QT:
I go to cmd and go there to folder:
cd J:/Users/shidant2/Desktop/workspace/qldt/qldt-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug
There I run this:
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT_OPENGL_ES_2_ANGLE -DQT_NEEDS_QMAIN -I..\qldt -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\include" -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtWidgets" -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtGui" -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtCore" -I"debug" -I"." -I"." -I"............\Qt\Qt5.0.1\5.0.1\mingw47_32\mkspecs\win32-g++" -o debug\main.o ..\qldt\main.cpp
Then I get my main.o !
And if I try to build main.o from QT Creator, it can not build this main.o.
Creator creates empty main.o, hangs some time without doing single thing
and after that it gives error as I posted in first message.
I suspect this can be something with permissions for QT in Windows 7.
But still can not figure out what is the problem.
Any suggestions, guys?
Thank you.
http://www.qtforum.org/article/38999/error-compiling-wrong-slash-used-in-makefile-debug.html
Is there a problem with the slashes it is using?
I have seen posts in which people say that Qt 5 projects are now required to add widgets to QT variable and this is why simple Qt example in netbeans doesn't work: cannot include QtGui/QApplication -> no such file or directory.
how to add this to QT variable? do I have to do it for each project in IDE or in .bashrc or somehowe?
the problem was because of link error. it was because it didn't link with QtWidgets.
g++ -m64 -Wl,-rpath,/opt/Qt5.0.1/5.0.1/gcc_64 -Wl,-rpath,/opt/Qt5.0.1/5.0.1/gcc_64/lib -o dist/Debug/GNU-Linux-x86/QtApplication_2 build/Debug/GNU-Linux-x86/main.o -L/usr/X11R6/lib64 -L/opt/Qt5.0.1/5.0.1/gcc_64/lib -lQt5Gui -lQt5Core -lGL -lpthread
first I have checked that using something from QtCore still works. the code was:
#include <QtCore/QCoreApplication>
int main(int argc, char *argv[]) {
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QCoreApplication a(argc, argv);
// create and show your widgets here
return a.exec();
}
and it was fine, so I knew it is only the linkage error.
I still didn't know what to add, as you don't have QtWidget in Qt tab on project Properties in Netbeans. but trial and error showed that it is enough to check the QtOpenGl on this tab (Modules), then it is linked against more libs:
g++ -m64 -Wl,-rpath,/opt/Qt5.0.1/5.0.1/gcc_64 -Wl,-rpath,/opt/Qt5.0.1/5.0.1/gcc_64/lib -o dist/Debug/GNU-Linux-x86/QtApplication_1 build/Debug/GNU-Linux-x86/main.o -L/usr/X11R6/lib64 -L/opt/Qt5.0.1/5.0.1/gcc_64/lib -lQt5OpenGL -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
I'm trying to compile a Qt Creator project on the command line. Here's what I did.
$ qmake
$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DALLOWSYNCING -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o main.o main.cpp
In file included from ./model/videostream.h:4:0,
from ./model/videostreamersession.h:4,
from view/videoplayerwindow.h:4,
from main.cpp:3:
./model/videoframe.h:5:18: fatal error: QImage: No such file or directory
compilation terminated.
make: *** [main.o] Error 1
It looks like make can't find the header files for Qt-related classes. How do I tell make where it can find them using an additional parameter or environment variable? I noticed some search paths are included by default, but in my environment they're located in /opt/QtSDK/Desktop/Qt/474/gcc/include/.
As requested, my PRO file. It was initially generated by Qt Creator so it's nothing out of the ordinary.
QT += core gui
TARGET = output
TEMPLATE = app
SOURCES += # Trimmed for brevity
HEADERS += # Trimmed for brevity
# Special build flags
DEFINES += ALLOWSYNCING
# These libraries are required for the program to operate
LIBS += -ljrtp -ljthread
CXXFLAGS="-I/opt/QtSDK/Desktop/Qt/474/gcc/include/" CFLAGS="-I/opt/QtSDK/Desktop/Qt/474/gcc/include/" LDFLAGS="/opt/QtSDK/Desktop/Qt/474/gcc/lib" make
However, you're probably on a mac I'm guessing.. In which case you should just export QT_DIR=/opt/QtSDK/Desktop/Qt/474/, and add /opt/QtSDK/Desktop/Qt/474/bin to your PATH and that should jiggle everything into place once qmake runs.
I installed QT4 Creator in /usr/programs/qt , I add to PATH /usr/programs/qt/bin,
QTDIR=/usr/programs/qt,LD_LIBRARY_PATH=$QTDIR/lib, and also for MANPATH and export. Problem is that demo examples work fine, but when I create new project in other directory for example /home/Jane/ it doesn't work, I got errors like
/home/Jane/test-build-desktop/../test/main.cpp:1:
error: QApplication: No such file or
directory
/home/Jane/test-build-desktop/../test/main.cpp:2:
error: QLabel: No such file or
directory
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}
Can anybody help me ?
Add to your .pro file:
QT += gui
I've the same problem. in my ".pro" file it was
QT -= gui
then I changed it to
QT += gui
and the problem solved
QApplication: No such file or directory ...
try to add
QT += widgets
at your .pro file. I had the same message... It looks like from 5.0 Qt-based applications does not like widgets by default...
The solution works for me, Qt 5.7
After added the following line to your .pro file:
QT += widgets
Right-click on your Qt Project and click "Run qmake"
Run qmake
After this when you re-complie your project, everything should be fine.
If your .pro file has this line:
QT -= gui
you need to delete it. It tells that the gui module to be removed from your app.
You can enable it by typing
QT += gui
but actually it is not needed since the gui module is enabled by default.
For Ubuntu 14.04 if you get the same error:
ABC$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I. -I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o textpad.o textpad.cpp
textpad.cpp:1:24: fatal error: QApplication: No such file or directory
#include <QApplication>
^
compilation terminated.
make: *** [textpad.o] Error 1
Try qmake-qt4 and then make. Of course you can get all the QT4 libraries if its not present using:
sudo apt-get install libqt4-dev