an error in qt_creator - qt

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.

Related

No such file or directory #include <QDebug>

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

make can't find Qt headers when compiling project on the command line

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.

How to compile a Qt application through the command line with MinGW?

I have downloaded the latest Qt version for MinGW, and I have the correct MinGW version which is compatible with Qt. When I try to make the project, g++ is unable to find my source file even if it's in the same folder as the project file.
Those are the steps I followed (all project and source files are in T:\QtTest ):
T:\QtTest> qmake -project
T:\QtTest> qmake
T:\QtTest> make
And the output is this:
T:\QtTest> make
mingw32-make -f Makefile.Debug
mingw32-make1: Entering directory `T:/QtTest’
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I“c:\Qt\4.8.0\include\QtCore” -I“c:\Qt\4.8.0\include\QtGui” -I“c:\Qt\4.8.0\include” -I”.” -I“c:\Qt\4.8.0\include\ActiveQt” -I“debug” -I“c:\Qt\4.8.0\mkspecs\default” -o debug\main.o main.cpp
g++: main.cpp: no such file or directory
g++: no input files
mingw32-make1: *** [debug/main.o] Error 1
mingw32-make1: Leaving directory `T:/QtTest’
mingw32-make: *** [debug] Error 2
I have no idea why it can't find "main.cpp" file when it's in the same directory as the
project files. Even if I replace "main.cpp" with the full path ("T:\QtTest\main.cpp") it still won't find it. What am I doing wrong?
The following is my project structure:
(main.cpp is the only file that I wrote, all the others were generated by qmake)
T:\QtTest\main.cpp
T:\QtTest\Makefile
T:\QtTest\Makefile.debug
T:\QtTest\Makefile.release
T:\QtTest\QtTest.pro
T:\QtTest\debug\
T:\QtTest\release\
My g++ version is 4.4.0, which is the version suggested by the Qt installer and available for download in the same page as the Qt for MinGW installer.
Problem solved.
It had nothing to do with MinGW or Qt or the makefiles generated by qmake. I found it was caused solely by a custom entry in the Windows registry. I'm posting this solution for anyone who encounters the same problem:
Sometime ago I had created an entry in the Windows registry under HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor called Autorun, which makes CMD.exe start in a custom working directory, which was something I wanted to do (so I followed the steps detailed in this page about "How to change the default startup directory for Command Prompt": http://windowsxp.mvps.org/autoruncmd.htm).
Well, I completely neglected the CAUTION part in that page, which states that "Changing the current directory using Autorun value as mentioned in this article, might affect the functionality of batch scripts". Yes, shame on me.
So, if you have the same problem of being unable to make your Qt projects using qmake, and everything else looks OK in your project structure and makefiles, verify that you don't have something in the Windows registry which might change the startup directory for the command prompt.
Do you have MSYS installed? If sh.exe from MSYS is on the system path, it may conflict with the interpretation of windows style paths. Check the documentation here.
If that isn't the problem, then delete everything in your project folder except the source files and start over again with qmake -project. After that step, open the .pro file and verify that things look correct. For a very basic project, I get something like this:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += widget.h
FORMS += widget.ui
SOURCES += main.cpp widget.cpp
The next two steps, running qmake and then make should work correctly. If not, there is nothing wrong with the steps you followed and there is something wrong with your system/environment.

building a Qt application outside the Qt sourcetree

I made a simple Qt application that's based on an Qt example application and builds fine from within the "examples" directory of the Qt sourcetree.
Now I want to move my project files to a different location but qmake fails to create a Makefile that can find the Qt header files.
The project files have been moved from ~/qt-everywhere-opensource-src-4.7.2/examples/webkit/fullscreenbrowser to ~/cvswork/fullscreenbrowser/
So the .pro file is now ~/cvswork/fullscreenbrowser/fullscreenbrowser.pro
And the Qt sources are still at ~/qt-everywhere-opensource-src-4.7.2
qmake itself runs fine, but make fails to load some includes:
$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_WEBKIT_LIB
-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB
-I/usr/share/qt4/mkspecs/linux-g++
-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork
-I/usr/include/qt4/QtGui
-I/usr/include/qt4/QtWebKit
-I/usr/include/qt4
-I.
-o main.o main.cpp
main.cpp:41:17: error: QtGui: No such file or directory
For comparison, when building under the ...examples... directory, the first g++ call is much different:
$ make
g++ -c -pipe -fno-exceptions -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG
-DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX
-DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_HAVE_SSE3
-DQT_HAVE_SSSE3 -DQT_HAVE_SSE4_1 -DQT_HAVE_SSE4_2 -DQT_HAVE_AVX -DQT_SHARED
-I../../../mkspecs/qws/linux-x86-g++
-I.
-I../../../include/QtCore
-I../../../include/QtNetwork
-I../../../include/QtGui
-I../../../include/QtWebKit
-I../../../include
-I.moc/release-shared-emb-x86
-o .obj/release-shared-emb-x86/main.o main.cpp
What do i have to configure so that the Qt source directory is found?
EDIT: The fullscreenbrowser.pro file can be seen here: http://pastebin.com/jUPJiWBC
EDIT2: I get the same behavior in the examples directory when adding -nocache to the qmake call.
That's actually more or less by design I think. Building inside the source folder needs to be a bit different than building against an installed tree, just to be able to do upgrades sanely for instance (prebuild everything in-place without referencing any existing build).
I believe that "trick" is done with a specific .qmake.cache file in the toplevel source folder (~/qt-everywhere-opensource-src-4.7.2 in your case) that is created when you configure the source tree (which happens to build qmake in there).
Try copying that file to your new build location (~/cvswork/fullscreenbrowser/ or ~/cvswork if you have other projects, it should look there too), and re-run qmake (making sure you use the one inside the Qt source directory).
This should work if you've simply configured the source tree.
Here's the first lines of that .qmake.cache file on my machine after having unpacked and configured an old Qt archive:
CONFIG += release shared dll largefile stl precompile_header mmx 3dnow sse sse2 sse3 ssse3 sse4_1 sse4_2 avx dylib create_prl link_prl depend_includepath fix_output_dirs QTDIR_build
QT_SOURCE_TREE = $$quote(/home/foo/src/qt-everywhere-opensource-src-4.7.3)
QT_BUILD_TREE = $$quote(/home/foo/src/qt-everywhere-opensource-src-4.7.3)
QT_BUILD_PARTS = libs tools examples demos docs translations
QMAKE_ABSOLUTE_SOURCE_ROOT = $$QT_SOURCE_TREE
QMAKE_MOC_SRC = $$QT_BUILD_TREE/src/moc
#local paths that cannot be queried from the QT_INSTALL_* properties while building QTDIR
QMAKE_MOC = $$QT_BUILD_TREE/bin/moc
QMAKE_UIC = $$QT_BUILD_TREE/bin/uic
QMAKE_UIC3 = $$QT_BUILD_TREE/bin/uic3
QMAKE_RCC = $$QT_BUILD_TREE/bin/rcc
QMAKE_QDBUSXML2CPP = $$QT_BUILD_TREE/bin/qdbusxml2cpp
QMAKE_INCDIR_QT = $$QT_BUILD_TREE/include
QMAKE_LIBDIR_QT = $$QT_BUILD_TREE/lib
QMAKE_LFLAGS = -Wl,-rpath-link,$$QT_BUILD_TREE/lib $$QMAKE_LFLAGS
QT_CFLAGS_PSQL = -I/usr/include/postgresql-8.4
QT_LFLAGS_PSQL = -L/usr/lib64/postgresql-8.4/lib64
QT_CFLAGS_MYSQL = -I/usr/include/mysql
QT_LFLAGS_MYSQL = -Wl,-O1 -Wl,--as-needed -rdynamic -L/usr/lib64/mysql -lmysqlclient_r -L/usr//lib64 -lz -lpthread -lcrypt -lnsl -lm -lpthread -L/usr/lib64/ -lssl -lcrypto
Q T_LFLAGS_ODBC = -lodbc
QMAKESPEC = $$QT_BUILD_TREE/mkspecs/linux-g++-64
...
As you can see, a lot of the fundamental qmake variables are overridden with that build tree prefix.
(Not sure why you don't simply install Qt somewhere in your home directory. You wouldn't have any of this pain, and you don't need root for that I think as long as the prefix is your own - haven't tried that in ages though, so YMMV.)
The example probably attempts to include a file from elsewhere in the hierarchy. For simple cases you can often generate a new project file as follows:
qmake -project # generate a project file using defaults
qmake # generate a makefile from the project file
make # build using the makefile
qmake will go through your directory recursively examining and including files. It's not smart enough to figure out everything, like every module you may need, but it does a good job on simple test projects. I usually do the above for all my spikes.

Qt Creator Error

Launching debugging for a project and then,
Running build steps for project Text_Editor...
Starting: "c:/qt/2010.05/qt/bin/qmake.exe" C:/Qt/2010.05/Text_Editor/Text_Editor.pro -r -spec win32-g++
The process "c:/qt/2010.05/qt/bin/qmake.exe" exited normally.
Starting: "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Qt/2010.05/Text_Editor-build-desktop'
C:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Qt/2010.05/Text_Editor-build-desktop'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\qt\include\QtCore" -I"..\qt\include\QtGui" -I"..\qt\include" -I"..\qt\include\ActiveQt" -I"debug" -I"..\Text_Editor" -I"." -I"..\qt\mkspecs\win32-g++" -o debug\main.o ..\Text_Editor\main.cpp
mingw32-make[1]: Leaving directory `C:/Qt/2010.05/Text_Editor-build-desktop'
mingw32-make: Leaving directory `C:/Qt/2010.05/Text_Editor-build-desktop'
g++: ..\Text_Editor\main.cpp: No such file or directory
g++: no input files
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make: *** [debug] Error 2
The process "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project Text_Editor (target: Desktop)
When executing build step 'Make'
I have no clue on that. I just installed it, created a new project and got that error instantly.
I had pretty much the same problem just now.
Without getting into "why" - I unticked "Shadow build" from project options and my build was succesful. Funny part is - "Shadow build" worked yesterday, and nothing really changed that much in between.
For reason or another it is not able to find your main.cpp (g++: ..\Text_Editor\main.cpp: No such file or directory). Basically that path should be ok if you have shadow build toggled on.
Location where the main.cpp is tried to find is:
C:/Qt/2010.05/Text_Editor/main.cpp
Double check that this is proper location (notice also case sensitivity to be sure)
you can try toggling off the shadow build from project -> check off shadow build. And also you should check that Text_Editor.pro contains properly the main.cpp.
Edit: It might be also wise to create that project outside the Qt binary folder, to some other more logical folder.
Try to change your build directory from C:/Qt/2010.05/Text_Editor-build-desktop to C:/Qt/2010.05/Text_Editor.
To do this just open your project in Qt creator, left click on Project on the left pane, then open build settings tab and edit Build directory input field.
What worked for me was the way I added headers in a .pri.
This works...
HEADERS += ../serialportwidget.h
HEADERS += ../serialportworker.h
SOURCES += ../serialportwidget.cpp
SOURCES += ../serialportworker.cpp
or this
HEADERS += ../serialportwidget.h \
../serialportworker.h
SOURCES += ../serialportwidget.cpp \
../serialportworker.cpp
This doesn't...
HEADERS += ../serialportwidget.h \ ../serialportworker.h
SOURCES += ../serialportwidget.cpp \ ../serialportworker.cpp
Run Qt Creator with "Run as Administrator".
Problem Solved for [debug/main.o] error5
-
Vivin NL

Resources