Qt component defines

David Faure faure at kde.org
Fri Aug 28 00:58:37 CEST 2009

On Thursday 27 August 2009, Thiago Macieira wrote:
> > I guess the problem is in KDE we do not do INCLUDE( ${QT_USE_FILE} )
> > because we do not use the QT_LIBRARIES var. The reason we do not do
> > that is with so many projects being configured in the same CMake pass,
> > QT_LIBRARIES would be useless: it would contain the sum of all the Qt
> > libraries any one project has requested at some time by using SET(
> > QT_USE_QTXXX 1).
> >
> > Maybe we should do INCLUDE( ${QT_USE_FILE} ) but keep on NOT using
> There's no need to change anything.

Well, IMHO it's a bug in Qt that QtTest uses QT_GUI_LIB.
See below for the email I sent to qt-bugs in April and the response I got.

> Those #defines are only used in QtTest. The KDE macros for adding
> executables could handle that (NOGUI -> don't add the QtGui #define).

But this is a solution too, I agree.

----------  Forwarded Message  ----------

Subject: Re: [Issue N250366] QTEST_MAIN creates a QCoreApplication instead of a QApplication
Date: Tuesday 07 April 2009
From: qt-bugs at trolltech.com
To: David Faure <dfaure at kdab.net>
Cc: qt-bugs at trolltech.com

Hi David,

On Sunday, 05. Apr 2009 02:12 David Faure wrote:
> The documentation for QTEST_MAIN says:
> "Implements a main() function that instantiates a QApplication object
> "
> but this is only true if QT_GUI_LIB is defined, otherwise it creates a
> QCoreApplication. This would be nice, except that nothing in Qt
> defines QT_GUI_LIB. This seems to come from qmake?

Indeed, this is pulled in by qmake which use qt.prf (in QTDIR/mkspecs/features) to check the QT variable and 
adds the appropriate QT_<module>_LIB defines.

> So this logic breaks with other buildsystems like cmake. It seems
> wrong to me that QTestLib relies on qmake being used. What about doing
> it cleanly, with a different macro for core-only and gui tests? That's
> what I did in KDE, where I forked QTEST_MAIN for other reasons (but
> the forking is the reason I didn't discover this bug earlier).
> #define QT_GUI_LIB is a workaround, after reading the source code, but
> this isn't obvious nor documented.

I agree, this should be documented, and I have passed a bug report onto the development team for 


I have also created a suggestion to add explicit macros for QCoreApplication and QApplication based tests. 
After all, we provide a QTEST_APPLESS_MAIN() macro whose feature may as well have been implemented by 
the QTEST_MAIN() macro, if neither the gui nor the core libraries are linked against:


Kind regards,

Stian Sandvik Thomassen, Support Engineer
Qt Software, Nokia


David Faure, faure at kde.org, sponsored by Nokia to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).

More information about the Kde-buildsystem mailing list