Qt vs MFC
Philippe Fremy writes: "I have just published and translated into English a comparison between Qt programming and MFC programming, which was written by Pascal Audoux (a fellow coworker). I am interested in feedback and would love to add quotes from developers that have used both toolkits." Here is the English version ("Qt vs MFC") as well as the French one ("Qt contre MFC").
Well, that's obvious. From the article:
;-)
The conclusion drawn from our personal experience is obvious. Qt is far better than MFC. You'll produce better programs with less hassle.
I do agree though.
DNA is the ultimate spaghetti code.
In Qt, objects are always open. There is not "Create()" function. What is when opening fails in the contsructor, does Qt use exceptions? If yes, then correct Qt code has to use "try {...}" on every creation of widgets. In other toolkits, "Create()" returns a BOOL, and you must use "if (Create()) {...}". I think the KDE developers admitted they didn't like exceptions. There's no problem in using exception, but if you write a Qt program, and derive classes from Qt classes, your classes will also throw exceptions in their constructor. Not everyone writes their code like that, and proting existing C++ apps may be difficult for that reason. The other way around, if a library uses "Create()", then wrapping around your own code which calls Create() in the constructor is not hard.
-- 1.e4 c6 2.d4 d5 3.Sc3 de4: 4.Se4: Sd7 5.Sg5 Sgf6 6.Ld3 e6 7.S1f3 h6 8.Se6:
And not portable. Remember, it is becoming more practical to take off the blinders and support other operating systems. Writing a new application to support both UNIX and Windows, for example, not only results in a better application architecture (abstracted for portability) but also distributes risk (so what if either Microsoft or Apple or Linux falls by the wayside; I'm covered).
So, to fight a troll with a troll:
Why use MFC...when Qt provides better risk mitigation and has been industry proven.
Healthcare article at Kuro5hin
Perhaps the most useful of all would be a comprehensive somparison of all the various toolkits/libraries.
Everything in the Universe sucks: It's the law!
I've been doing lots of Qt, GTK and Java programming, a few months ago I needed to start hacking on a MFC project. I tell you, never ever again. I'm now having a cronic headace, thanks alot MS. And what is it with those API's on Windows, do they have to typedef _everything_ for every different occasions, I'm sure I encountered 20 different typedef s for "unsigned int" just browsing through some MSDN pages. Not to mention the joy of unwinding a structure so you can get to business. Theres a structuer with a structure, member, with a member,with... And they each have members of type unsigned int, WORD, p_WORD, uint32. If somone know how to make apis and code even more unreadable I'm sure there is an open job somewhere near Redmond.
And not portable
You could always recompile with the help of MainWin, but the performance is horrible. This is essentially what Microsoft uses to port IE to UNIX. That's why wxWindows and Qt are very appealing to me right now.
"...today consumers have been conditioned to think of beer when they see a bullfrog..."
Frankly MFC is a pain. It is pretty buggy in places. I did not like this artical all that much. It was pretty shallow to asy the least. wxWindows looks very interesting and there is a very good artical on porting MFC code to it in IBMs website.
See my blog http://ilovecookes.blogspot.com/ for light hearted technical information.
This is a bit of a strange review:
...
I always thought that comparisons had to be done with some kind of objectivity, if only for the purpose of decency... Apparantly this is not the case: MFC was produced by hordes of rabid monkees while God himself came down and Created Qt.
Even not a C/C++ developer myself, I don't see a lot of proof / illustration to the MFC side and way too much positive adjectives on the Qt side: "genious", "excellent",
The best one was probably:
"One of the stated goal of Trolltech is "The product and the documentation should be so good that no support is needed".
QED...
Qué?
----
--
[insert witty one-liner here for your own pleasure]
While I wholehartedly agree with the conclusion, I must say that the article is a mess and feels like it was written by a 16-year old. It's barely comparative, sticking to the format that feature X is messy in MFC and much easier in Qt, and here's an example of just how easy. He doesn't give any MFC code examples, mainly limiting himself to explaining the horrors of Unicode and resources. An objective reader could hardly take this for a serious comparison of the two frameworks.
Besides, it's really comparing apples and oranges. Anyone who's used the MFC at all knows that it's hardly OO. A much fairer comparison would be that of Qt to Borland's VCL. In many respects they're very, very similar, but it seems that the nod of more consistent OO design would go to the VCL. I base this mainly on the event-handling semantics of both toolkits. While Qt falls back to straight C (or possibly even a macro? shudder!) for connecting an event handler to a component, the VCL stays faithfully OO, implementing event handlers as method pointers (exposed as properties) on components.
Continuing the example used in the article, Qt reads:
connect( button, SIGNAL( clicked() ), SLOT( action() ) );
while the VCL would read:
button.OnClick = action;
Anyway, as I said, while I support the conclusion of the article, based on its lack of maturity I wouldn't use it to try to convert existing MFC programmers.
This guy doesn't seem to understand much of what he's talking about.
The most glaring clue is this:
For example, to swap two variables, the author used the non commented following line:
a ^= b ^= a ^= b;
This is a cool hack which does not belong to a professional product.
If you don't recognize this, you probably need to go back to school. It's fast, and it doesn't require a temp variable.
Any time you look at low level libraries, you're going to see things like this. They NEED speed. They NEED low memory impact. These things are going to get called in tight loops with a million iterations. Look at QT's code, and you'll see the same thing.
Also telling is the fact that he has nothing positive to say about MFC. I've run across some VERY talented developers, and while I haven't heard them singing MFC's praises, they do have some nice things to say. Advocacy really needs to show balance. Acknowledging MFC's strong points is important.
When he's talking about an add on library called 'codejack', he mentions that tab views are impossible in MFC, yet codejack provides it. Apparently it is NOT impossible in MFC then. It probably isn't a prebuilt widget for the developer to use (which is unfortunate, I'll admit)
QT is a good library, I have no doubt. But please learn how to find good things in other libraries. It will only make your code better. It will only make your advocacy better.
Zapman
That is one thing i have to disagree with the article. MSDN is quite good. And if you are using MFC, then you are using VC++. That means help is usually just an F1 click away.
As others have mentioned, the article is really badly written. I cannot comment on the merits of Qt, since I've done practically nothing with it. But I've done my fair share of MFC, and it's quite ugly - I find it hard to believe that *anything* solving a comparable problem can be much worse.
But my main point is this: When dealing with stuff like MFC you need to factor in the quite helpful development tools that the Visual Studio suite consists of. I have yet to see something of that quality from anyone else (except possibly Borland), and so far I've found only KDevelop to be reasonably useful. The MFC library (I flatly refuse to call it an object model) is ugly, but to some extent this is ameliorated by the IDE. I *know* this is not the way it should be done, but it's there and it DOES help...
Black holes are where God divided by zero
See question 3.3b.
Qt is a wrapper around the native calls (Windows API, X API, Macintosh WindowMgr/ControlMgr API, etc).
So why is it bad for MFC (where you go from EnableWindow(window, verb) to window->Enable(verb)), but good for QT?
Perhaps I deserve it for not previewing and seeing that the formatting was all screwed up :).
> MFC is much faster
I have never seen any facts in one direction or the other, could you point me to your references ?
My experience is that both MFC and Qt are fast. With usually less flickering in Qt.
One thing that is sure however, is that MFC is not faster in term of development speed.
Beaten... why? I think it's fun :-}
You're right on both counts. See this Usenet post for a little more detail.
It's always a long day... 86400 doesn't fit into a short.
Why is MainWin's performance so slow? Is it slower than porting with winelib would be?
"Writing a new application to support both UNIX and Windows, for example, not only results in a better application architecture (abstracted for portability) but also distributes risk (so what if either Microsoft or Apple or Linux falls by the wayside; I'm covered)."
I think your second point is valid, but your first, not always. If portability is not a requirement, the architecture is not improved by the introduction of an abstraction that doesn't model the problem. In addition, comprehensive compatibility would require that the application be portable to other operating systems in addition to those based on Windows or Unix.
I don't think there are many Windows programmers using MFC for new development. A comparison of Qt and .NET would be more relevant.
We had an MFC vs wxWindows discussion, where Qt and others were of course brought up, and it was MUCH more informative. See here.
I personally use QT, its feature rich and the cross platform ability is obviously a large benefit.
As a previous poster mentioned the VCL is really nice too, its just a shame that I have to use Object Pascal to use it I hear a C++ version is coming to Linux though.
As for MFC I don't really like it, it just doesn't feel object orientated enough!
However, MFC isn't that bad. If you're developing a Windows application in C++, and you're forced into using MS only technology cause your boss won't pay the $1000+ per developer license for QT, and your choices are between using MFC and the base Win32 API, then MFC is the way to go. Granted, the Document / View Architecture is uh... well it's *odd*, but once you get the hang of it you can whip out a reasonably good GUI quickly.
MFC does do some nice things for you, mainly serialization and treating controls as objects, and the Message Maps are a vast improvement over the 10 page switch statements for Message Handling in Win32..
However, since MFC is "dead", I'd rather see a comparision between C# and Windows Forms vs. C++ and QT.. (and a lot of this I posted on Microsoft's own news groups.. hehehehe)
Seriously, If you want to see something that's godawful, look at C# and Windows Forms.
The below is from a post I submitted to Microsoft's own news groups.. to date, I have not gotten any kind of response from Microsoft. A couple of "Wait for Borland C++ Builder.NET" responses.. but nothing from Microsoft. Since MFC is "dead" and .NET is the "way" for Microsoft now, it makes sense to post this..
Especially if you have an option between QT and .NET... PICK QT FOR THE LOVE OF GOD.
While trying to develop a dockable tool window (much like the ones found in Visual Studio.NET) I've done a lot of research and had a lot of grief. Out of the box, you can't create a dockable window.
No one seems to know of any royalty free, open source solutions, and the .NET Magic library doesn't count. Look closely at the source and
you'll find that there's an awful lot of Win32 API calls being made
via PInvoke, which, per Petzold on page 237 of "Programming Windows
with C#", is "no longer writing managed code, and certainly not
platform-independent code."
So for the .NET Magic library users, what's the point of even
bothering to use C# and Winforms if all you're using it for is to wrap
Win32 API calls? Why not just use C++ compiled as a Win32 app and get
the performance increase and greater toolset? I know that making it a
dockable window is just a window style, (FWS_something, too lazy to
look it up right now, which you would think would just be a property
of a Control type, since Control seems to Map 1 to 1 to a Window.)
Which brings me to the largest gripe I have about the .NET framework:
The Winforms really suck. The overly simple UI controls it exposes are
simply not acceptable in today's enviroment. First, I'll give
Microsoft credit: Visual Studio.NET's UI is absolutely stunning, and
the C# language has some nice features....
However, it is seemingly impossible to create any form of advanced UI unless you derive your own controls or use PInvoke to create GenericPane window classes. And according to Spy++, those nice dockable, resizable windows are of Window Class GenericPane. Seriously, take Docking toolbars for example - we've been able to do this in MFC for years, so using "pure" C# really seems like two steps back instead of the leap forward the PR machine would have you believe. For any kind of advanced UI are we really forced to pony up money for third party libraries or roll our own? (And again, for the goal of "pure" C#, using PInvoke doesn't count.)
What's really maddening is that there's so many other language / RAD toolkits that do this much better. C++ / MFC, C++ / QT (for cross platform), Java / Swing, to name a few.
Even the Menus aren't dockable / moveable. What's the point of using managed code if the only applications you can quickly produce look like crap?
(my apologies to Wired Magazine)
Tired: MFC
Wired: System.Windows.Forms
Anyone creating an app from scratch right now, or porting an app not written in MFC, should _not_ be even considering MFC. New MFC enhancements are usefull for maintaing the (large) base of MFC apps written in it over the last ?10? years. It's time is over though.
-Malakai
A Dragon Lives in my Garage
I don't know why everyone is claiming MFC is no longer in the picture after .Net. It's like claiming Newspaper was dead after TV came out. Here is an excerpt from MSDN:
.NET, MFC and C++ developers may be feeling left out. But don't worry--with the upcoming release of Visual Studio .NET, not only do developers using Visual C++® get a brand new IDE with tight integration for server-side development and a much improved C++ compiler, MFC and ATL have also received significant new features. The clear message is that MFC continues to be a great framework for developing sophisticated, rich client applications for all Windows® platforms. In this article, we'll provide you with a survey of the new features that you can use in your MFC applications.
It has been three years since the last major update to MFC and ATL. With all the press on Microsoft®
There's a new MFC DLL (MFC70.DLL) that is no longer backward binary-compatible with MFC42.DLL, but your source is still compatible (although message maps have been made more type-safe, so that may break some code).
MFC and ATL are much better integrated, and common classes such as CString are now shared between the two libraries.
Header files are synchronized with the latest Platform SDK, supporting UI features in Windows 2000 and Windows XP such as themes and manifest resources, Active Accessibility®, and new common dialog boxes.
Many new UI classes have been added, including support for using DHTML in dialog boxes and enhanced bitmap support with CImage.
New utility classes can be used in both MFC and ATL applications, such as regular expressions, performance counters support, and security.
Now there's support for consuming Web Services in MFC applications and writing Web Services and applications with ATL Server classes.
High-performance access to databases has never been easier using the new OLE DB attributes and classes.
STL has been updated.
I haven't used QT, but my experience with MFC has been:
D FC' scattered all over it. And you can just pull values out of a dialog box; you have to use this thing called "Direct Data Exchange" that I never really figured out, and you have all these magic cookies that get defined in some header file somewhere and you don't even get to write main() and all the functions have weird names and at least we have a good String class but all the classes start with the letter 'C' and everything is in hungarian notation and all those weird macros and WHERE DO I DRAW STUFF IN MY WINDOW?! and BLAH BLAH BLAH!!!
MFC is the most confusing, bloated, needlessly complex, poorly-designed API in the world.
First, you use this little program called 'AppWizard', that asks you a few question like if you want toolbars, if you want database support (database support?), if you want OLE, etc. Then it spits out this hulk of code that has all these weird constants and macros in them with names like '__AFX_DEFINED_DDLXCI_AXWEC_UBER_MACRO_EXCHANGE_D
I write in Java now.
I can't help feeling that, whatever its position on MFC, the article was unjust in its uniform praise of Qt. Some of the container classes there (QMap?) appear to be somewhat inferior versions of the STL equivalents, in case the C++ library in use doesn't support the STL parts properly, but doesn't support all the template guff required to use them(?!) To their credit, they do at least try to support the standard interfaces so you can use their containers with standard algorithms, which is a definite improvement over MFC.
The article also seems to praise QString, which is yet another string class with a Big Bloated Interface(TM) (doh!) that thinks using only mutable strings is the way forward (double-doh!) and reference counting/copy-on-write of a mutable string is a Good Thing (double-plus-doh!). These are well-known design flaws with both approaches, relating to efficiency, thread safety, etc. If they wanted an improvement, they should have provided an immutable string class with a suitable set of operations, and a string-building framework to go with it where it's genuinely the appropriate tool. Oh, and being in native Unicode isn't particularly clever. Why not just use std::wstring, anyway?
As for the graphics, sometimes I want to lay out my dialog controls in exactly the positions I decide to put them in. Dynamic generation can be a good thing, but don't mandate it, because sometimes it's simply wrong.
I also have quite a bit of experience of i18n, and I'm all-too-familiar with the pain of translations, etc. For those who don't know, l10n (the opposite to i18n, i.e., making your location-generic application work in a specific locale) is about 10% translation and 90% integration, fixing up all the dialogs, ensuring that your UI can cope with reordered sentences (hope you don't like the IOStreams approach; printf had it right years ago) and so forth. A simple tr() function is not the silver bullet here, contrary to what the article seems to suggest.
Don't get me wrong, I think Qt is a nice library, and much better than many of the alternatives. But some of the claims in the article are just downright false.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
I assume from the rest of your post that you're advocating using .NET instead? Why on earth would any development team of sound mind do that?
MFC, OTOH, while kludgy and less than well-designed, has a developer base of zillions across the world who know how to work around its kludginess and get the job done. It is tried and tested, so at least you have a pretty good idea where the bugs are. There is a lot of truth to the old saying "Better the devil you know".
If I had a new development team starting on a Windoze app, MFC certainly wouldn't be my first choice of tool -- far from it -- but it would be waaaaay ahead of anything to do with .NET.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
Would that be the same Don Box who wrote about how COM was wonderful for years, but now says it's crap and we should all use .NET?
You should be very careful when listening to two-faced Microsoft weenies, particularly when they're demonstrably wrong. MFC was used in writing Visual Studio itself for a long time (though never, AFAIK, in writing things like Office).
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
I agree, there's also ATL i think that's even worse!!! I found it far easier to write using straight windows API.
Fortunatly I wrote my own Windows wrapper before MFC came along.
MFC might look good in comparison to Visuial Studio which must be one of the worst Dev environments I've ever used, I'd never take a job where Visuial studio was a requirement.
thank God the internet isn't a human right.
here
borland has Just released Kylix 3with C++ and Object Pascal support in one product.
/. yet?
Don't know why this hasn't made it to
thank God the internet isn't a human right.
Microsofts help was ok when it was in plain help files It just got shit when monkey soft switched to HTML help forcing everyone to install IE.
thank God the internet isn't a human right.
Qt doesn't use abstraction in the same sense of (for example) AWT. It implements its own widgets for each target "look and feel". The down-side is that you possibly end up with something that looks slightly different from the target platform (no emulation is perfect), but you don't suffer the same performance impact or awkwardness (for example, the logical intersection of all targets problem)
The Microsoft Foundation Class (MFC) is a graphical toolkit for the windows operating system. It is a more or less object oriented wrapper of the win32 API, which causes the API to be sometimes C, sometimes C++, and usually an awful mix.
The only non-C++ you could complain about in MFC is the use of some Win32 API structures without containing classes/accessors. Under the circumstances (given the number of them!) I don't think this is too big a deal.
MFC programming requires the use of Document/View model and templates.
No, it doesn't. If you don't want Doc/View, you can just use the MFC-dialog-application template.
I've never seen the other problems you mention:
- you can probably ditch the document/view model (I've never tried) but you can easily bury it if you don't like it and I've never found it inflexible enough to be a hinderance. Cite an example?
- I wouldn't be surprised if splitting a window to show two different documents probably violates the windows UI design guidelines. You can get equivalent function using an MDI app (although I think the guides have deprecated those) or implement a 'document container' class or something. You probably don't need too much imagination.
MFC is a kind of object wrapper allowing access to the windows API,I'd consider this a plus - lean (or as lean C++ as you'll get), efficient (ditto) and feature-complete.
And there are nasty tricks, without any consistency. For example, if you create a graphical object, it is not created until the Create() methods has been called. For dialogs, you must wait for OnInitDialog, for views, you wait for OnInitialUpdate,
No. This *is* consistent and logical. And OO.
- When you create a CDialog, you create a container class for a window handle with dialog-like methods. You may set up the initial state of the dialog, member variables of the container class, etc. But because you have an empty handle you can't actually play with the dialog yet.
- You Create() or DoModal() your CDialog object. Now the windows is actually generated on the desktop and the window handle is filled.
- You're called back in the OnInit* method to set any state on the window as it is created. You may now call methods that require a window handle.
I don't think MFC will crash - I think it'll give you a useful debug assert. But I haven't fallen into that trap for a while.MFC is full of these nasty tricks. And it is hard to debug.
'nasty tricks' is a little extreme. MFC integrates very well with Visual Studio's debugger and is relatively simple to debug. You're provided with the source code to step through if you need it. I've never had any trouble.
Qt is based upon a powerful callback mechanism based on signal emission and reception inside slots.
This sounds exactly like the Windows message model that you've just slammed (!). I don't see any problems with the windows message model - but then I'm familiar with the API.
The interface creation section: DDX and IMPLEMENT_DYNCREATE (why do you need that for your UI?) are relatively easy to understand - maybe try Prosise's book if you need enlightenment. You don't need to touch the message loop - it's buried in the MFC DLL and covers all cases. You can quite happily manufacture dialogs at run-time by calling Create() on control objects in the OnInitDialog() method.
Qt designer lets you do things that are not possible in MFC, like creating a listview with pre-filled fields, or using a tab control with different views on each tab.
Pre-filling a list view should be done in OnInitDialog(); the interface is quite simple.
Tabs are a different matter; you need to create child dialogs for each separate pane. This closely reflects what's going on in the OS API. It's not too difficult and there are good sample applications. Alternatively, there's a very simple interface to create complex property pages already provided.
Visual's documentation, MSDN (for which you must pay separately) is huge, on 10 CDROM.
It's no more than 3 CDs. It's bundled with Visual Studio. It's available online at http://msdn.microsoft.com/library/. And it's very good, complete documentation.
MFC's unicode is very easy. If you need to change the entry point of your application then you're doing it wrong; you probably need to change
If you're given non-unicode third party library then the third party ought to be able to supply a unicode version by changing a few flags and rebuilding. I'd be surprised if many vendors couldn't supply Unicode libraries if you asked them.
Resources and string-tables are part of the Win32 API. I find them useful and easy to program for. You have to try quite hard to load resources from the wrong DLL; all resources are indexed on exe/dll module handle as well as resource ID.
Latest MFC DLL: you should always ship the one you develop and test against! Win2K+ allows you to install a copy of the DLL local for your application. Alteratively, there are simple-ish mechanisms to auto-download the latest MFC from Microsoft.
To address some of your list of QT advantages,
- Controls... MFC uses native OS widgets which is arguably an advantage for Win32 programs: correct look and feel and always do exactly what a Windows user would expect.
- MFC does provide classes for network and database access
- Memory management shouldn't be a problem; if you create controls as members of the containing dialog class then they'll be destroyed automatically too. MFC's debug memory allocator is good, too.
I've never used CodeJock.Do people really have to look any farther to figure out why today's software is so buggy? The more subtle "gotchas" in a language, the more subtle bugs in the resulting products.
I understand the lure of mastering reams of arcane trivia. In fields like medicine, this is valuable. But, when you have to do so just to use a man-made programming language because of how often things are not what they appear, it is a stinging indictment of the poor design of the language.
"Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
1st download a trial copy of CBuilder or Delphi and give there IDE a go...
.....
...
Here's my top hates....to the point of frastration.
1: (this is trully evil) the MDI interface.
2: Dialogues have loads of tabs but arn't resizeable.
3: Options arn't natural, e.g. right click on a project and I get
4: (part of 3) Options are hidden all over the place.
5: MSDN HTML help is shit (not the use of HTML for help, but the way MS have used it)
Here's a few things in CBuilder Delphi (as an example) that are farrrr superior.
1: No evil MDI
2: Options are quite easy to find
3: Fully RAD
4: Code compleation is highly typed e.g.
int a =
only lists things that can return or be cast to an int.
5: The help is generally quite good.
6: The api for extending CBuilder/Delphi is great and easy to use (easier than Visual Studio).
thank God the internet isn't a human right.
So you'd rather have a 'grown-up' but non-OO and kinda ugly language than one with a flexible and powerful object model, RTTI, inheritable message-handling framework, copy-on-write strings, etc., etc.?
All the current hype over .NET is old hat: Delphi has had most of what .NET has to offer for years (not surprising given who wrote them both ).
Object Pascal makes me much more productive than C++ ever did, and I'm not talking about GUI gubbins here, but the 'invisible' back-end stuff.
What's interesting about qt is that its easy to get an app to run both on the desktop and then have a smaller screen version for qtopia.
Check my site out for ogg vorbis music produced with linux.
And i got rejected
* 2002-07-23 13:28:19 Kylix 3 out soon (articles,news) (rejected)
grrrrrrrrrr
The best exposition I've seen was a set of three articles on "Reference Counting" in Herb Sutter's Guru of the Week series. You can find articles 43-45 on his web site, and as he notes there, an updated version is available in one of his books. You could also search the history for the Usenet group comp.lang.c++.moderated, where GotW is posted, to see more discussion on the subject. You might also want to check out the most recent GotW (questions but no solutions on the web site, but check the newsgroup history) for a few thoughts on why string classes tend to have overbloated interfaces.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
The main problem with QT is this thing called MOC, some kind of preprocessor you need to run. Then of course, there's the license fee for use in any commercial software. Other than that, there's just the use of Expose events in X11 making it slow and ugly.