[CMake] find_package(Qt4 REQUIRED) doesn't include QtNetwork?

Clinton Stimpson clinton at elemtech.com
Fri Mar 4 14:10:19 EST 2011


On Friday, March 04, 2011 11:59:07 am kent williams wrote:
> To use Qt in my projects with CMake, up until now all it seemed to
> require was this:
> 
> find_package(Qt4 REQUIRED)
> include(${QT_USE_FILE})
> 
> But then I tried to use QTcpServer and QTcpSocket, and the compiles
> failed because it couldn't find the include files.

Were you doing this: #include <QtNetwork/...>,
or setting QT_USE_QTNETWORK=1 somehow before include(${QT_USE_FILE}),
or your own include_directories() somewhere?

> 
> Then I read through the FindQt4.cmake file that comes with CMake
> 2.8.4, and found that I could fix the problem with
> 
> find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED)

find_package(Qt4 REQUIRED QtCore QtGui QtNetwork) will set QT_USE_QTNETWORK=1 
for you.

> 
> But I'm confused that all my programs I built before I tried to use
> networking had worked.  I thought the first, simpler find_package
> statement would just include everything by default.  Is that wrong?

The simpler find_package() defaults to QtCore and QtGui modules being enabled.  
It has always been that way.

Clint


More information about the CMake mailing list