QtCreator autocomplete not working (headers included elsewhere)



  • Hello,
    I'm a Qt newbie.
    Today I've noticed that if I include my header files in another file - let's say I have a file, Utilities.cpp, and that file is included in my mainwindow.h header (where QTextStream is included), which in turn is included in mainwindow.cpp - then the autocomplete will not work when I write code using the QTextStream class in Utilities.cpp. In short, it seems that for the autocomplete to work the given header file must be included in the very same file I'm writing to.

    Is there any way around this?


  • Moderators

    This is Qt Creator teaching you how to code correctly. If you use a class in a file, include it's header. Always. Even if you have already included it elsewhere.

    The reasons for this are the following:

    1. When you rearrange the code, it may happen that the compiler will loos the view of a header included in another file. You will be flooded with error messages about X not being defined, or an incomplete class, etc. If you always include all the headers you need in the file, you will never have this problem.
    2. Making sure you only inlcude the headers you need and where you need them will speed up compilation.


  • Indeed, that works beautifully. Thanks a lot :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.