Important: Please read the Qt Code of Conduct -

Cmake in QtCreator: Headers and includes

  • Hi there,

    I'm using qtcreator with cmake to code a C++ library. As the library is supposed to be light and doesn't need to do any GUI, I'm not actually coding against Qt.

    I've just recently decided to convert to cmake -- before I was using hand-written makefiles :-S -- and I've found two issues with qtcreator (though it could well be me not using cmake appropriately)

    1. I've got many header files *.h and *.hxx which are included in several *.cpp files but do not show up in the project tree on qtcreator, is there any way of telling qtcreator that those files do belong to the project?

    2. I'm using boost threads, but for some reason qtcreator doesn't expand the macros well and doesn't include the implementation headers (in my case pthreads), which results on it giving me undefined type warnings when the compiler has no trouble finding said types. I thought I could hack this by just feeding qtcreator a definition (BOOST_THREAD_PLATFORM_PTHREAD) but I don't want to mess up the compilation. Anyway I can do this?

    I tested with QtCreator 2.0.1 in MacOS X 10.6.6 and QtCreator 2.0.0 in Ubuntu 10.10.

    Thanks in advance,
    Miguel S.

  • Hi,

    I've an answer only for point (1). Locate the point where you set the sources for your projects (i.e. cpp files), and add .h and .hxx too.

    Like this example:

    set( MY_SRCS

    Reload everything in QtCreator and you'll see all your files.

  • Hi,

    Thanks a lot! That worked perfectly :) I had assumed adding the headers to the sources variable would confuse cmake (thought it might try to compile the headers) but both cmake and qtcreator do the right thing.

    Any clues about the second point? I'm really addicted to auto-completion :P

    Thanks again,
    Miguel S.

Log in to reply