Channels ▼

Community Voices

Dr. Dobb's Bloggers

QT vs MFC

July 19, 2009

In the latest post MFC was analyzed by CppDepend to discover some metrics and design,
in this article the goal is to analyze QT and compare it to MFC.

Qt is a cross-platform application development framework, used for the development of
GUI programs and also used for developing non-GUI programs such as console tools
and servers.

You can download QT from http://www.qtsoftware.com/products/, and to analyze it with
CppDepend you need Visual studio addin from
http://www.qtsoftware.com/downloads/visual-studio-add-in  to convert .pro
to vcproj format.

QT Analysis
After converting .pro to .vcproj we can launch the analysis with CppDepend.



QT solution contains 259 projects,many projects are only for test and the interesting ones
are: QTCore, QTGui, QTNetwork,QTXml and QTSql.
And to compare QT to MFC we analyze only the previous ones.




GUI components:

For this layer it’s better to have a maximum of components to avoid selling other
frameworks or developing them,so which framework contains more components?

For MFC any component is derived from CWnd and for QT is derived from QWidget.

Let’s search with CppDepend all classes derived from CWnd and QWidget.

For MFC there are 221 Gui components and for QT only 142 widgets.


But which one propose more functionalities and behaviors?
Let’s search for public methods of QT Edit component.


QT propose more public methods than MFC , for example it’s very easy to change
the background color of QT edit component and I remember that I spend
many times to do that with MFC. 

For Gui layer MFC propose more components but QT propose more functionalities.

Activex support:


COM technology is a good solution for many problems,
but unfortunately the misunderstanding of this technology makes it very complex
and many architects avoid it.

We have to consider COM technology only as a wrapper over POCO classes
to adapt them to be used with other languages, so this layer can be developed
by only one developer, the problem is that the development team makes COM
the kernel of the application and begins the development with them.

QT propose activeqt project to manage ActiveX but MFC has a complete
support for OLE and ActiveX than QT.


Networking support


QT propose classes for many khown networking protocols.



MFC support also all these protocols, and for this functionality QT is equal to MFC.

XML support:

QT gives classes to parse DOM and Sax, it's very simple to use and MFC treat
xml through COM components,So you have to know some automation basics
and types.
QT is easy to use than MFC when manipulating XML.

Design


QT is well designed than MFC, it use many patterns ,
for example data are in general isolated into classes which names end
with "Private" like QWidgetPrivate.


MVC Pattern


MFC propose CDocument/CView concept to implement MVC pattern, as explained in the latest post
avoid use CDocument as your model but only as controler.

MFC provide also functionalities like saving, printing, OLE embedding, and the Doc/View provide a design
of your application,but we have to be careful when using a technical framework that proposes an architecture;
it can makes the project less flexible.

For QT MVC is very used for gui components, let's take for example QPushButton and QRadioButton,
they use the same model QAbstractButton.

and we can also observe the existance of QStyle in this dependency graph,
so the Style is isolated to permit many look and feel.




And QT propose also the concept of signal and slot that makes easy the programming of event handling.

Abstractness vs Instability:

The "Abstractness vs Instability" graph can be useful to detect projects that will be difficult to maintain or evolve.
This following post describe the utility of this graph and how to exploit it to improve the design.

For QT here's the "Abstractness vs Instability" graph:

only QtCore is inside the zone of pain , because it's very used by other projects and not contains sufficient abstract classes.

Conclusion:


So the question is which framework use? both are very intersting and the choice depend of our needs.
You can choose MFC if :

- The application will be deployed only in windows.
- ActiveX and OLE embedding support is needed.
- You need sophisticated Gui components like ribbon.
- The application need Doc/View concept, MFC treat archiving,printing,OLE embeding so you can gain many times.

And for MFC the good solution is to develop classes that hides the complexity of some needs,
to reuse them in all projects using MFC and to avoid to develop them each time.

QT is the best choice if the application must be deployed in many platforms,
and if it's planed to deplyed only in windows it can be used if:

- The developement focus more on design.
- it's difficult to find human resources : recently it's not easy to find C++ developer,
 and for a C++ beginer developer QT is more accessible than MFC.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video