QT vs MFC
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
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.
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.
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.
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.
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.
QT propose classes for many khown networking protocols.
MFC support also all these protocols, and for this functionality QT is equal to MFC.
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
QT is easy to use than MFC when manipulating XML.
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.
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:
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.