Qt what headers to include?

前端 未结 4 1429
我在风中等你
我在风中等你 2021-02-20 11:42

While programming in C++ with Qt what includes should I make? Just 2 includes

#include 
#include 

or



        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 12:10

    Include only the definitions of the classes you need - anything else isn't just lazy, it's extremely wasteful and to my mind bad style.

    Including QtGui (which itself includes QtCore) will lead to adding about 350(!) header files to your compilation, when in your example you only needed 6. Compiling will take longer, and when someone tries to maintain your app and is browsing your files they won't be able to infer from just the includes what exactly it is each file/class is trying to do - they'll have to read the entire source to get an idea.

提交回复
热议问题