Qt包含哪些标题? [英] Qt what headers to include?

查看:110
本文介绍了Qt包含哪些标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Qt在C ++中进行编程时,我应该包括哪些内容?仅2个包含

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

#include <QtCore>
#include <QtGui>

#include <QWidget>
#include <QDialog>
#include <QList>
#include <QKeyEvent>
#include <QObject>

每堂课?

谢谢!

推荐答案

仅包含您需要的类的定义-其他任何东西不仅很懒,而且非常浪费,在我看来,这是不好的风格.

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.

包括QtGui(本身包括QtCore)将导致在编译中添加大约350(!)头文件,而在您的示例中,您仅需要6.编译将花费更长的时间,并且当有人尝试维护您的应用时,浏览您的文件时,他们将无法仅从包含内容中推断出每个文件/类试图执行的操作-他们必须阅读整个源文件才能获得想法.

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.

这篇关于Qt包含哪些标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆