Qt 是否被归类为 c++图书馆?如果不是库,你会如何对 QT 进行分类?
我最近开始研究 Qt(我安装了 Qt 4.5.2 并安装了名为“qt Integration v1.5.2”的 Eclipse-CDT 插件,我将在 Linux-Eclipse-CDT-QTintegration 中进行所有开发)。
最初我认为 Qt 是一个普通的 C++ 库,但是当我安装并开始运行 Qt 示例代码时,我看到了很多我认为是非标准的“奇怪”的东西。
我的目标是在高抽象层次上理解:
- Qt 是否被归类为 C++ 库?
- 如果不是库,您会如何对 Qt 进行分类(赞赏类比/隐喻)?强>
I recently started looking into Qt (I installed Qt 4.5.2 and installed their Eclipse-CDT plugin called "qt integration v1.5.2" and I will do all my development in Linux-Eclipse-CDT-QTintegration).
Originally I thought Qt was a straight vanilla C++ library but when I installed and started running Qt example code I saw lots of "weird" things that I consider to be non-standard.
My goal is to understand at a high level of abstraction:
- Is Qt classified as a C++ library?
- If not a library, how would you classify Qt (analogy/metaphors are appreciated)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Qt 是一个框架,而不是一个库。这并不是编程语言强制执行的硬性区别,而是描述了代码的设计方式和使用方式:
库是其他人的代码,供您使用。代码。使用库意味着您的应用程序保持原样,只是有另一个库来帮助它。
框架是您的代码适合的其他人的代码。使用框架意味着框架定义了应用程序的结构。
如果您正在使用框架,则需要学习该框架的约定,这可能与基础语言略有不同;否则,您可能会花费大量时间与框架作斗争,并且您将错过它所提供的一些功能。
特别是 Qt 看起来不像直接的普通 C++,因为它不是直接的普通 C++。它为 C++ 的对象系统添加了(有限的)扩展,以允许信号和槽等功能;这些扩展是使用 Qt 的 moc 实现的,它充当 C++ 预处理器。有关 Qt C++ 扩展的更多信息:
Qt is a framework, not a library. This isn't a hard-and-fast distinction enforced by the programming language, rather, it describes how the code is designed and intended to be used:
A library is someone else's code that is used by your code. Using a library means that your application remains as it is, it just has another library to help it out.
A framework is someone else's code that your code fits into. Using a framework means that the framework defines the structure of your application.
If you're using a framework, you need to learn that framework's conventions, which may be a bit different than the base language; otherwise, you can spend a lot of time fighting the framework, and you'll be missing out on some of what it has to offer.
Qt in particular doesn't look like straight vanilla C++ because it isn't straight vanilla C++. It adds (limited) extensions to C++'s object system to permit features like signals and slots; these extensions are implemented using Qt's moc, which acts as a C++ preprocessor. For more information on Qt's extensions to C++:
Qt 是一组 C++ 库以及一个预处理器和构建系统的一部分。
Qt is a set of C++ libraries along with a preprocessor and part of a build system.
大多数 GUI 框架/库都会添加到该语言中,只是因为 C++ 本身不支持(或者直到最近才支持)GUI 所需的事件类型。
Qt 选择通过语言扩展和预编译器来实现此目的,MFC 和 wxWidgets 通过 C 宏和 C 预处理器来实现此目的。
Qt 方法意味着它可以做更多事情(不受 cpp 宏语言的限制),但代价是构建环境稍微复杂一些。
Most gui frameworks/libraries add to the language, just because C++ doesn't (or didn't until very recently) natively support the kind of events you need for a gui.
Qt chooses to do this with extentions to the language and a pre-compiler, MFC and wxWidgets do this with c macros and the c-preprocessor.
The Qt approach means it can do more (it's not limited by the cpp macro language) at the expense of a slightly more complicated build environment.