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
Related
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.
I am getting an error when trying to link a static boost_filesystem library with QMake.
I know that my boost install is working, because I can link to it no problem outside of QMake like this:
g++ -o my_file my_file.cpp -IC:\boost_1_55_0\boost_1_55_0 -LC:\boost_1_55_0\boost_1_55_0\stage\lib -lboost_system -lboost_filesystem
I tried linking Qt with boost_filesystem like this at first, but it seems that it could not find the libraries:
LIBS += -LC:\boost_1_55_0\boost_1_55_0\stage\lib -lboost_system -lboost_filesystem
"-lboost_system not found -lboost_filesystem not found"
I read something about how you need to specify absolute paths to static libs when using QMake, so I've changes my LIBS line in my .pro to the following:
LIBS += "C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a" \
"C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a"
The libraries are found with this method, however I get the following error message:
undefined reference to boost::system::generic_category()
I was under the impression that this error only happen when boost_system isn't linked! I seems like it is linked though, because it finds the proper library for it, and I know my install of boost is good because the same library links fine (with the same compiler) outside of Qt Creator.
Here's the include in mainwindow.h:
include <boost/filesystem.hpp>
Here the full .pro:
QT += core gui
QT += network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QMAKE_CXXFLAGS += -std=c++11
TARGET = Downloader
TEMPLATE = app
INCLUDEPATH += C:\boost_1_55_0\boost_1_55_0
LIBS += "C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a" \
"C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a"
SOURCES += main.cpp\
mainwindow.cpp\
rar_process.cpp\
HEADERS += mainwindow.h\
rar_process.h\
FORMS += mainwindow.ui
RESOURCES += \
graphics.qrc
And here's the full compiler output:
C:\Qt\Qt5.1.1\5.1.1\mingw48_32\bin\qmake.exe -spec win32-g++ -o Makefile ..\qt- downloader\Downloader.pro
C:/Qt/Qt5.1.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/Patrick/Desktop/cpp/build-Downloader- Desktop_Qt_5_1_1_MinGW_32bit-Release'
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Downloader.exe release/main.o release/mainwindow.o release/rar_process.o release/qrc_graphics.o release/moc_mainwindow.o release/moc_rar_process.o -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a - LC:\Qt\Qt5.1.1\5.1.1\mingw48_32\lib -lQt5Widgets -lQt5Network -lQt5Gui -lQt5Core
release/main.o:main.cpp:(.text.startup+0x1a): undefined reference to `boost::system::generic_category()'
release/main.o:main.cpp:(.text.startup+0x24): undefined reference to `boost::system::generic_category()'
Makefile.Release:86: recipe for target 'release\Downloader.exe' failed
c:/qt/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686- w64-mingw32/bin/ld.exe: release/main.o: bad reloc address 0x24 in section `.text.startup'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [release\Downloader.exe] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/Patrick/Desktop/cpp/build-Downloader- Desktop_Qt_5_1_1_MinGW_32bit-Release'
makefile:34: recipe for target 'release' failed
GCC is very sensitive to the order in which you specify libraries during the linking stage. For example, if libA.a depends on libB.a and an executable App depends on both, then you'd have to invoke linker in the following way:
gcc main.o object1.o ... object2.o -lA -lB -o App
This implies that you have to change it to:
LIBS += "C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a" \
"C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a"
To be cross-platform, it's recommended to make your build more robust:
Boost_VERSION = 1_55
COMPILER = mgw48
win32-g++* {
LIBS += $$(Boost_DIR)/stage/lib/libboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION}.a \
$$(Boost_DIR)/stage/lib/libboost_system-$${COMPILER}-mt-$${Boost_VERSION}.a
PRE_TARGETDEPS += $$(Boost_DIR)/stage/lib/libboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION}.a \
$$(Boost_DIR)/stage/lib/libboost_system-$${COMPILER}-mt-$${Boost_VERSION}.a
}
linux-g++* {
LIBS += -L$$(Boost_DIR)/stage/lib -lboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION} \
-lboost_system-$${COMPILER}-mt-$${Boost_VERSION}
PRE_TARGETDEPS += $$(Boost_DIR)/stage/lib/libboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION}.a \
$$(Boost_DIR)/stage/lib/libboost_system-$${COMPILER}-mt-$${Boost_VERSION}.a
}
NOTE: Boost_DIR would be treated as an environment variable here. So that you can flexibly build it on any system without hardcoding the system-dependent path to Boost. This is general practice in professional software development: try to hardcode as little as possible in your build system, whatever it is. Furthermore, it's reasonable to even make Boost_VERSION environment variable too. All you'd have to change then, are brackets to parentheses, i.e. $${Boost_VERSION} to $$(Boost_VERSION).
Finally, notice that I've used forward slash / as a path separator for both Windows and Linux. Backward slash \ is not only deprecated in QMake, but it is also discouraged in general. Once again, be cross-platform: simply let QMake handle the conversion.
Apparently boost-system will not link against mingw gcc 4.8.0 if it was built with mingw gcc 4.8.1.
I re-built boost with mingw gcc 4.8.0 and linked against those libs, and now it works!
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
I begin to study qt (I have qt creator, last version), so I read the reference how to begin to work with it and I'm trying to compile project "Animated Tiles" but I receive an error, can somebody please explain why:
Running build steps for project animatedtiles...
Configuration unchanged, skipping qmake step.
Starting: "D:/QT_prog/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `D:/QT_prog/qt/examples/animation/animatedtiles-build-desktop'
D:/QT_prog/mingw/bin/mingw32-make -f Makefile.Debug all
mingw32-make[1]: Entering directory `D:/QT_prog/qt/examples/animation/animatedtiles-build-desktop'
mingw32-make[1]: Nothing to be done for `all'.
mingw32-make[1]: Leaving directory `D:/QT_prog/qt/examples/animation/animatedtiles-build-desktop'
D:/QT_prog/mingw/bin/mingw32-make -f Makefile.Release all
mingw32-make[1]: Entering directory `D:/QT_prog/qt/examples/animation/animatedtiles-build-desktop'
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\include\QtCore" -I"..\..\..\include\QtGui" -I"..\..\..\include" -I"..\..\..\include\ActiveQt" -I"tmp\moc\release_shared" -I"..\animatedtiles" -I"." -I"..\..\..\mkspecs\win32-g++" -o tmp\obj\release_shared\main.o ..\animatedtiles\main.cpp
..\animatedtiles\main.cpp:257:20: error: main.moc: No such file or directory
mingw32-make[1]: Leaving directory `D:/QT_prog/qt/examples/animation/animatedtiles-build-desktop'
mingw32-make: Leaving directory `D:/QT_prog/qt/examples/animation/animatedtiles-build-desktop'
mingw32-make[1]: *** [tmp/obj/release_shared/main.o] Error 1
mingw32-make: *** [release-all] Error 2
The process "D:/QT_prog/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project animatedtiles (target: Desktop)
When executing build step 'Сборка'
Looks like the main.moc file hasn't be generated.
Try this:
Clean the Project "Build" -> "Clean All" or "Clean Project "
Build the project again, Ctrl+B
If that doesn't work then:
Comment out the #include "main.moc" line at the end of main.cpp
Perform a build, moc should run and create main.moc, but the build will fail.
Uncomment #include "main.moc", and build again. Should work
Edit:
I'm not very familiar with qt creator, so you might also want to try just remove the #include "main.moc" line altogether. QMake might be smart enough and figure out what to do.
The suggested solution did not work for me. I had to copy main.moc from release_shared up to the directory containing main.cpp. QT 2010.05, Win7.
I think you are experiencing this:
http://bugreports.qt.io/browse/QTCREATORBUG-1889
I was able to reproduce this issue with Qt SDK 2010.04.
Install Qt SDK 2010.04 on Windows 7
Open animatedtiles
Build
Removing c:\Qt\2010.04\qt\exmaples\animation\animatedtiles\tmp\moc\release_shared\main.moc manually solved the issue.