View Full Version : wrapper in C for QT

29th October 2007, 12:35
Hello, All !

I develop wrappers in C for C++ library, which was make with QT class library. Which way I have to include header files from QT into my .c file


#include <QObject>

If I try to make project using qmake utility and in pro file write

QT += core

then I receive many error messages such this

gcc -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/opt/xgis/include/xgis -I/opt/gdal/include -I. -I. -o search.o search.c
In file included from /usr/include/qt4/QtCore/qobjectdefs.h:42,
from /usr/include/qt4/QtCore/qobject.h:44,
from /usr/include/qt4/QtCore/QObject:1,
from /opt/xgis/include/xgis/searchengine.h:9,
from search.c:1:
/usr/include/qt4/QtCore/qnamespace.h:46: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QT_MODULE’
/usr/include/qt4/QtCore/qnamespace.h:1424: error: expected ‘)’ before ‘:’ token
/usr/include/qt4/QtCore/qnamespace.h:1440: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Q_CORE_EXPORT’

29th October 2007, 14:37
You're funny - you include a c++ header in a c file, compile this with a c - compiler instead a c++ one and then you wonder why you get errors? :crying:

29th October 2007, 15:12

I understand my error therefore I'll write 2 files cpl_searchengine.h and cpl_searchengine.cpp, may I use C++ methods in realization ?

29th October 2007, 19:11
Yes, this should work and imho you have no other chance :)

29th October 2007, 21:06
Thanks a lot, all works fine.