PDA

View Full Version : Qt failing to compile claiming "fatal error: QObject: No such file or directory"



Momergil
29th October 2015, 17:15
Hi!

I have a project developed in Qt 4.8 for Embedded Linux and Linux that compiles fine. Now I'm trying to compile it in Qt 5.5.1 in Windows 7 and I got a problem I'm being unable to solve: each time I try to compile it, I get the error


C:\Qt\Qt5.5\5.5\mingw492_32\bin\uic.exe interface\dialogs\alphanumerickeyboard.ui -o build\uis\ui_alphanumerickeyboard.h
g++ -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DV_SERGIPETECH_0=0x100 -DV_SERGIPETECH_1=0x101 -DV_UNILA_0=0x110 -DGENERAL_VERSION_NUMBER=V_UNILA_0 -DAPP_VERSION=\"\" -DMAIN_CLOCK=1000 -DSCREENSAVER_SIMPLE_MODE -DCENTER_CONTROLLER -DPERIODIC_WIDGETS_UPDATE -DSAVE_ENTIRE_PQ -DDEFAULT_THEME_PATH='"D:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../..\main_projects\interface\theme"' -DDEFAULT_DATA_PATH='"D:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../..\main_projects\interface\data"' -DDEFAULT_TRANSLATION_PATH='"D:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/translations"' -DDEFAULT_SCREENSHOT_PATH='"C:\Users\Administrador\Imagens\screenshots"' -DDEFAULT_RECORD_DIR='"C:\Users\Administrador\Documentos\TEMP\LogsRE8000"' -DDEFAULT_PENDRIVE_DIR='"C:\Users\Administrador\Documentos\TEMP\PendriveRE8 000"' -DDEFAULT_VERSION_FILE_PATH='"C:\Users\Administrador\Documentos\TEMP\version.inf o"' -DCALIBRATION_FILE='"C:\Users\Administrador\Documentos\TEMP\caltouchpoi nts"' -DDEFAULT_ETC_PATH='"C:\Users\Administrador\Documentos\TEMP"' -DDESKTOP -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_XML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN qtextension/qcycleimagebutton.cpp -o qtextension/QCycleImageButton
In file included from qtextension/qcycleimagebutton.cpp:1:0:
qtextension/qcycleimagebutton.hpp:4:19: fatal error: QObject: No such file or directory
#include <QObject>
^
compilation terminated.

for the same file, which starts as such:


#ifndef QCYCLEIMAGEBUTTON_H_
#define QCYCLEIMAGEBUTTON_H_

#include <QObject>
#include <QAbstractButton>
#ifdef DESKTOP
#include <QtDesigner/QDesignerExportWidget>
#else
#define QDESIGNER_WIDGET_EXPORT
#endif

#include "interfaceglobal.hpp"

class QLabel;
class QImageButtonIllustration;
class QImageSliderIllustration;

typedef qint32 button_id;

class QDESIGNER_WIDGET_EXPORT QCycleImageButton : public QAbstractButton
{
Q_OBJECT

I can assure the Qt installation went OK since I created a QWidgets project and it compiled fine. I also checked if there was anything special in the Projects configuration but I couldn't find any problems there.

I also tried to find solutions to this problem on the web, but nothing helpful was found. Here is my .pro file as for now (minus the .hpp and .cpp includes):


QT += core gui xml network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

#CONFIG += qwt
#CONFIG += qwtpolar

RE8K_REPO = $${PWD}/../../..
RE8K_COMMON = $${RE8K_REPO}/common
RE8K_SDCARD = $${RE8K_REPO}/../../sdcard_files/defaultFiles
RE8K_TRANSLATION = $${RE8K_REPO}/main_projects/interface/translations

VERSION = $$system(svn info -r HEAD . | grep 'Changed\ Rev' | cut -b 19-)

DEFINES += "GENERAL_VERSION_NUMBER=V_UNILA_0"
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
#DEFINES += CLASSE_A_TEST
#DEFINES += INTERFACE_DEMO #Special for the demo version
DEFINES += MAIN_CLOCK=1000

DEFINES += SCREENSAVER_SIMPLE_MODE
#DEFINES += DATASTREAM_THREAD
DEFINES += CENTER_CONTROLLER
DEFINES += PERIODIC_WIDGETS_UPDATE #Enable update by 1 sec of all top level widgets to counter black screen bug
DEFINES += SAVE_ENTIRE_PQ #When selecting one item of a Physical Quantity makes all items be saved in a record
#DEFINES += SAVE_XML_TEST
#DEFINES += XML_WITH_COMMENTS
#DEFINES += RELEASE_VERSION
#DEFINES USE_FULL_CURRENT_RANGE_CONFIG #Enables current range of all 4 channels

INCLUDEPATH += $${RE8K_COMMON}/include
INCLUDEPATH += qtextension

LIBS += -L$${RE8K_COMMON}/lib #needed for hal, etc.
LIBS += -lQDeviceWatcher

CONFIG(debug, debug|release) {
LIBS += -lmLoggerd
}

CONFIG(release, debug|release) {
LIBS += -lmLogger
}

win32 {
DEFINES += 'DEFAULT_THEME_PATH=\'\"$${RE8K_REPO}\main_projects\interface\theme\"\''
DEFINES += 'DEFAULT_DATA_PATH=\'\"$${RE8K_REPO}\main_projects\interface\data\"\''
DEFINES += 'DEFAULT_TRANSLATION_PATH=\'\"$${RE8K_TRANSLATION}\"\''
DEFINES += 'DEFAULT_SCREENSHOT_PATH=\'\"C:\Users\Administrador\Imagens\screenshots\"\''
DEFINES += 'DEFAULT_RECORD_DIR=\'\"C:\Users\Administrador\Documentos\TEMP\LogsRE8000\"\''
DEFINES += 'DEFAULT_PENDRIVE_DIR=\'\"C:\Users\Administrador\Documentos\TEMP\PendriveRE8 000\"\''
DEFINES += 'DEFAULT_VERSION_FILE_PATH=\'\"C:\Users\Administrador\Documentos\TEMP\version.inf o\"\''
DEFINES += 'CALIBRATION_FILE=\'\"C:\Users\Administrador\Documentos\TEMP\caltouchpoi nts\"\''
DEFINES += 'DEFAULT_ETC_PATH=\'\"C:\Users\Administrador\Documentos\TEMP\"\''

DEFINES += DESKTOP

INCLUDEPATH += C:\Qt\Qwt-6.1.2\include
INCLUDEPATH += C:\Qt\QwtPolar-1.1.1\include
INCLUDEPATH += ..\..\..\third_party\mLogger\src
INCLUDEPATH += ..\..\..\third_party\QDeviceWatcher\src

LIBS += -LC:\Qt\Qwt-6.1.2\lib
LIBS += -LC:\Qt\QwtPolar-1.1.1\lib

TARGET = name_here
}

Any help appreciated.

Momergil
4th November 2015, 18:13
Moving thread up!

anda_skoa
5th November 2015, 09:38
Your compiler call doesn't seem to have any of the include paths you've specified.
Have you tried without any of those?

Also it might be necessary to escape the \ in the paths, especially in the DEFINES.
For the DEFINES maybe even better use forward slashes.

Cheers,
_

Momergil
11th November 2015, 14:12
Your compiler call doesn't seem to have any of the include paths you've specified.
Have you tried without any of those?

Also it might be necessary to escape the \ in the paths, especially in the DEFINES.
For the DEFINES maybe even better use forward slashes.

Cheers,
_

Thanks anda_skoa for the reply, but I confess I don't know what to do with the comments you gave me appart from the backslash which I put as an attempt to solve the problem (but I already put the back to forward slashes).

Regarding not having the include paths, yes, that's true: comparing the Output result of compiling the app for Desktop in Linux vs. Windows I get:



//Linux
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DV_SERGIPETECH_0=0x100 -DV_SERGIPETECH_1=0x101 -DV_UNILA_0=0x110 -DGENERAL_VERSION_NUMBER=V_UNILA_0 -DAPP_VERSION=\"335\" -DMAIN_CLOCK=1000 -DSCREENSAVER_SIMPLE_MODE -DCENTER_CONTROLLER -DPERIODIC_WIDGETS_UPDATE -DSAVE_ENTIRE_PQ -DDEFAULT_THEME_PATH='"/home/maiquel/Projects/RE8000/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/theme"' -DDEFAULT_DATA_PATH='"/home/maiquel/Projects/RE8000/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/data"' -DDEFAULT_TRANSLATION_PATH='"/home/maiquel/Projects/RE8000/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/translations"' -DDEFAULT_SCREENSHOT_PATH='"~/Pictures/screenshots"' -DDEFAULT_RECORD_DIR='"/home/maiquel/Documents/TEMP/LogsRE8000"' -DDEFAULT_PENDRIVE_DIR='"/home/maiquel/Documents/TEMP/PendriveRE8000"' -DDEFAULT_VERSION_FILE_PATH='"/home/maiquel/Documents/TEMP/version.info"'
-DCALIBRATION_FILE='"/home/maiquel/Documents/TEMP/caltouchpoints"' -DDEFAULT_ETC_PATH='"/home/maiquel/Documents/TEMP"'
-DDESKTOP -DQT_NO_DEBUG -DQT_XML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.8.5/mkspecs/linux-g++-64 -I. -I/usr/local/Trolltech/Qt-4.8.5/include/QtCore -I/usr/local/Trolltech/Qt-4.8.5/include/QtNetwork -I/usr/local/Trolltech/Qt-4.8.5/include/QtGui -I/usr/local/Trolltech/Qt-4.8.5/include/QtXml -I/usr/local/Trolltech/Qt-4.8.5/include -I../../../common/include -Iqtextension -I/usr/local/include -I/usr/local/qwt-6.1.0/include -I/usr/local/qwtpolar-1.1.0/include -Ibuild/mocs -Ibuild/uis -o build/objs/qcycleimagebutton.o qtextension/qcycleimagebutton.cpp

//Windows
g++ -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DV_SERGIPETECH_0=0x100 -DV_SERGIPETECH_1=0x101 -DV_UNILA_0=0x110 -DGENERAL_VERSION_NUMBER=V_UNILA_0 -DAPP_VERSION=\"\" -DMAIN_CLOCK=1000 -DHAS_GPS -DSCREENSAVER_SIMPLE_MODE -DCENTER_CONTROLLER -DPERIODIC_WIDGETS_UPDATE -DSAVE_ENTIRE_PQ -DDEFAULT_THEME_PATH='"D:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/theme"' -DDEFAULT_DATA_PATH='"D:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/data"' -DDEFAULT_TRANSLATION_PATH='"D:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/translations"' -DDEFAULT_SCREENSHOT_PATH='"C:/Users/Administrador/Imagens/screenshots"' -DDEFAULT_RECORD_DIR='"C:/Users/Administrador/Documentos/TEMP/LogsRE8000"' -DDEFAULT_PENDRIVE_DIR='"C:/Users/Administrador/Documentos/TEMP/PendriveRE8000"' -DDEFAULT_VERSION_FILE_PATH='"C:/Users/Administrador/Documentos/TEMP/version.info"' -DCALIBRATION_FILE='"C:/Users/Administrador/Documentos/TEMP/caltouchpoints"' -DDEFAULT_ETC_PATH='"C:/Users/Administrador/Documentos/TEMP"' -DDESKTOP -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_XML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN qtextension/qcycleimagebutton.cpp -o qtextension/QCycleImageButton


It's easy to see that both the includes of INCLUDEPATH as well as those of the Qt libraries are missing. The funny fact is that they are in the Makefiles!!



//Makefile.Release
...

CC = gcc
CXX = g++
DEFINES = -DUNICODE -DV_SERGIPETECH_0=0x100 -DV_SERGIPETECH_1=0x101 -DV_UNILA_0=0x110 -DGENERAL_VERSION_NUMBER=V_UNILA_0 -DAPP_VERSION=\"\" -DMAIN_CLOCK=1000 -DHAS_GPS -DSCREENSAVER_SIMPLE_MODE -DCENTER_CONTROLLER -DPERIODIC_WIDGETS_UPDATE -DSAVE_ENTIRE_PQ -DDEFAULT_THEME_PATH='"D:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/theme"' -DDEFAULT_DATA_PATH='"D:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/data"' -DDEFAULT_TRANSLATION_PATH='"D:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../../main_projects/interface/translations"' -DDEFAULT_SCREENSHOT_PATH='"C:/Users/Administrador/Imagens/screenshots"' -DDEFAULT_RECORD_DIR='"C:/Users/Administrador/Documentos/TEMP/LogsRE8000"' -DDEFAULT_PENDRIVE_DIR='"C:/Users/Administrador/Documentos/TEMP/PendriveRE8000"' -DDEFAULT_VERSION_FILE_PATH='"C:/Users/Administrador/Documentos/TEMP/version.info"' -DCALIBRATION_FILE='"C:/Users/Administrador/Documentos/TEMP/caltouchpoints"' -DDEFAULT_ETC_PATH='"C:/Users/Administrador/Documentos/TEMP"' -DDESKTOP -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_XML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN
CFLAGS = -pipe -fno-keep-inline-dllexport -O2 -Wall -Wextra $(DEFINES)
CXXFLAGS = -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads $(DEFINES)
INCPATH = -I. -I..\..\..\common\include -Iqtextension -IC:\Qt\Qwt-6.1.2\include -IC:\Qt\QwtPolar-1.1.1\include -I..\..\..\third_party\mLogger\src -I..\..\..\third_party\QDeviceWatcher\src -IC:\Qt\Qt5.5\5.5\mingw492_32\include -IC:\Qt\Qt5.5\5.5\mingw492_32\include\QtWidgets -IC:\Qt\Qt5.5\5.5\mingw492_32\include\QtGui -IC:\Qt\Qt5.5\5.5\mingw492_32\include\QtANGLE -IC:\Qt\Qt5.5\5.5\mingw492_32\include\QtXml -IC:\Qt\Qt5.5\5.5\mingw492_32\include\QtNetwork -IC:\Qt\Qt5.5\5.5\mingw492_32\include\QtCore -Ibuild\mocs -Ibuild\uis -IC:\Qt\Qt5.5\5.5\mingw492_32\mkspecs\win32-g++
LINKER = g++
LFLAGS = -Wl,-s -Wl,-subsystem,windows -mthreads
LIBS = -lmingw32 -LC:/Qt/Qt5.5/5.5/mingw492_32/lib -lqtmain -lshell32 -LD:/Desenvolvimento/RE8000SW/src/trunk/main_projects/interface/re8k_interface/../../../common/lib -lQDeviceWatcher -lmLogger -LC:/Qt/Qwt-6.1.2/lib -LC:/Qt/QwtPolar-1.1.1/lib -lqwt -lqwtpolar -lQt5Widgets -lQt5Gui -lQt5Xml -lQt5Network -lQt5Core
QMAKE = C:\Qt\Qt5.5\5.5\mingw492_32\bin\qmake.exe

...


So for some reason although qmake seems to be generating the Makefiles correctly, they are not being correctly obeyed by MinGW when it's called. Any suggestions?

Momergil
19th November 2015, 20:32
So far I've done the following:

I created a new project and started adding each header and source file one by one. I managed to discover some of the files which, once included, would trigger the error. Then I started doing the same for one of those files: including line by line of code.

What I managed to find was that if I moved the instantiation of a class object to the source file (with the header including the problematic qimagebutton.hpp), the error appears. If I then move back, the error continues and persists till I completely erase the files, deletes the makefiles and rebuild everything again.

Ultimately I noticed that I was including qimagebutton.hpp indirectly in the same way we include Qt classes: creating a file without extension, putting the include inside and then including the extensionless file in the project: #include <QImageButton>. I decided, then, to remove this adding the file directly and problem solved! (at least so far).

So, for some reason, MinGW seems to dislike such indirect includes.

AlekseyK
6th December 2020, 03:08
Yep, thanks, had same problem – indirect includes. Solved differently: changed indirect include file name to be different from class and header name:

class name: MyWorkItem
header name: "MyWorkItem.h"
indirect include name: <MyItems>, which contains:



#include "MyWorkItem.h"
#include ...

d_stranz
6th December 2020, 18:06
Solved differently: changed indirect include file name to be different from class and header name:

This sounds like superstitious voodoo to me. The build toolchain shouldn't care what you name your classes and files so long as Make has a rule for any file that must be transformed during the build. Header files, indirect or not, aren't usually transformed themselves, but as part of a compilation unit that is, like a .ccp -> .o rule.

The entire Qt distribution is based on indirect include files as well as the letter-envelope paradigm using opaque private classes to implement functionality exposed by public-facing classes and APIs. In all cases I can think of, the indirect include file, the actual include file, the public class cpp file and the class itself all have the same names.