Slashdot Mirror


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").

57 of 126 comments (clear)

  1. Re:Why would you use Qt? by pmz · · Score: 2

    .. when MFC is much faster...

    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).

    ...and has been industry proven.

    ...to be a kludge.

    So, to fight a troll with a troll:

    Why use MFC...when Qt provides better risk mitigation and has been industry proven.

  2. wxWindows comparison... by eyepeepackets · · Score: 2

    ...would be nice too since wxWindows is growing in popularity. Any one have experience using both wxWindows and MFC? Maybe a comparison between wxWindows and QT would be useful and interesting as well..

    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!
  3. Re:Why is this on slashdot? by pmz · · Score: 2

    Qt is far better than MFC. You'll produce better programs with less hassle.

    Very true. Literally within an hour or two, by following TrollTech's tutorial, a person can write and understand working GUI applications. One of Qt's strengths (and a tribute to its design) is how its learning curve is really quite low.

  4. "MFC programming", what the heck? by noselasd · · Score: 2, Insightful

    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.

    1. Re:"MFC programming", what the heck? by dthable · · Score: 2, Insightful

      And what is it with those API's on Windows, do they have to typedef _everything_ for every different occasions...

      Could it be to support more than a single machine architecture? Windows NT used to run on Alpha boxes and now, the move to IA-64 means that an unsigned int is going to change size. They typedef everything to ensure that no matter what platform they move to, the framework doesn't require major changes.

    2. Re:"MFC programming", what the heck? by RocketJeff · · Score: 2

      Actually, a lot of the mess in MFC is not due to the changing Win32 API, but left over from the switch from 16-bit Windows (i.e. 3.11) to 32-bit Windows (95/NT & later).

      It's this backwards compatablity that hampered MFC through too many years. Unfortunately, the only way to get rid of it now would be to start over (which will never happen now that .net is MS's future).

    3. Re:"MFC programming", what the heck? by Ben+Hutchings · · Score: 2

      uid_t and pthread_t are useful - they are the types used to hold a user ID or a thread ID. They can and do vary between implementations. Likewise types such as uint32_t and int_least16_t (from the C99 standard) are useful.

      The WORD and DWORD types do not provide an abstraction and do not obviously have any particular numeric properties. I happen to know that the names WORD and DWORD come from x86 assembler and are signed 16-bit and 32-bit quantities, but a portable API should be using names like INT16 and INT32 for such types instead. Some of the other types are more reasonable, but the API is not that consistent.

      All the pointer-to typedefs should be got rid of; they may have been somewhat useful under Win16 but are no longer relevant. UINT and ULONG are likewise fairly pointless.

      In a few places the Win32 API could do with more use of typedefs, for example for process and thread IDs (currently DWORDs).

  5. Good conclusion, poor article by uradu · · Score: 5, Insightful

    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.

    1. Re:Good conclusion, poor article by uradu · · Score: 2

      > Just curious: if button.OnClick and action are both method pointers,
      > how can you have more than one action in response to a click?

      Well, you're right, you couldn't in the current implementation. The simple method pointers on the components would have to be replaced by some sort of object with Add and Remove methods of its own, which would then insert the event handler assigned into some notification data structure. Basically you'd be "OO-fying" what connect() does in Qt. It would likely have more overhead than the Qt approach, so it's a matter of what you value more, OO-ness or performance.

    2. Re:Good conclusion, poor article by BdosError · · Score: 2
      Well, you're right, you couldn't in the current implementation. The simple method pointers on the components would have to be replaced by some sort of object with Add and Remove methods of its own, which would then insert the event handler assigned into some notification data structure
      Actually, you could (and they might) handle this by overloading the assignment operator (assuming VCL is in C++, I'm not familiar with it) so that it did in fact do an Add(). There are issues with this, and it would need to be fleshed out (and you'd have to figure out how to make a semantically similar Remove(), which is problematic), but it's possible. Mostly I'm arguing for pedantry's sake.
      --
      Complexity is Easy. Simplicity is Hard.
    3. Re:Good conclusion, poor article by uradu · · Score: 2

      > The problem it that it is hard to isolate a MFC example.

      You've got a point, but you can still give the steps required to hook up a buttong to an event handler. Doing that would have actually strengthened the argument considerably, precisely because VS is such a mess.

      > I encourage you to write it, that would be interesting.

      Hey, it's easier to criticise than to create, so I'll restrict myself to that, thank you very much.

      > And I don't see your point with fairness.

      I meant that as in Qt towering head and sholders above the MFC in the criteria chosen, finding faults in the MFC was almost like taking candy from kids. I was just thinking about comparing Qt to a similarly OO framework.

    4. Re:Good conclusion, poor article by uradu · · Score: 2

      > Actually, you could (and they might) handle this by overloading the
      > assignment operator (assuming VCL is in C++ [..])

      It isn't, though, it's in Object Pascal, which doesn't support operator overloading. You could still do it by changing the event handler method pointers to pointers to a singleton object that did the same work as connect() via an Add() method, without incurring any memory overhead per event handler per component.

      > you'd have to figure out how to make a semantically similar Remove()

      Well, in C++ you could simply overload the following operators:

      += : add this event handler
      -= : remove this event handler
      = : clear event handlers, then add this one

      I believe that's the mechanism they're using in C# with delegates (except maybe for the third one).

    5. Re:Good conclusion, poor article by uradu · · Score: 2

      > Actually the CLX library [...] is based in the Qt library.

      True, but that should be thought of as an implementation detail. You code to the CLX, not to Qt. Theoretically Borland could in the future rewrite the CLX on each platform straight to the metal without using Qt, and your programs should still compile. In practice they probably did surface some Qt here and there, maybe data structures taken as parameters of some methods, same as they did with win32 in the VCL.

    6. Re:Good conclusion, poor article by Lord+Omlette · · Score: 2
      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.
      As an MFC programmer who has discovered the glory of WinForms, lemme tell you: if we're not getting paid for it, we don't need any convincing to move from MFC to greener pastures.
      --
      [o]_O
  6. Advocacy, we never knew thee. by Zapman · · Score: 3, Insightful

    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
    1. Re:Advocacy, we never knew thee. by uradu · · Score: 2

      > But please learn how to find good things in other libraries.

      That's hardly a sign of a well-balanced comparison. You can completely blast a product and still have a fair review--IF the product really sucks in the criteria chosen, and you can fully document why and how it sucks. Unfortunately this author didn't do that, blasting the MFC on generalities without giving specific code examples, which OTOH he was more than eager to provide for Qt. Within the criteria used--OO design and ease of use--the MFC would pitifully fail against Qt, but you wouldn't know it reading this article.

    2. Re:Advocacy, we never knew thee. by Anonymous Coward · · Score: 2, Insightful
      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.
      Uh. I hope you don't really think that. Otherwise, I think it's time for you to go back to school. And no, nothing like that is to be found in Qt. Because its completely wrong, unpredictable, and best of all, the result is undefined. Have you ever read the C FAQ? Or comp.lang.c.moderated? No? I didn't think so.

    3. Re:Advocacy, we never knew thee. by pong · · Score: 2
      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.
      Actually I totally agree with you - the author of the article is completely biased. None-the-less it is extremely interesting to note the number of applications Microsoft itself has released that uses MFC.

      According to Don Box (COM guy, now works at Microsoft) the number is 0 - zero! nil! (He mentioned it in his keynote address at Microsoft Developer Days 2001 in Copenhagen)

      Food for thought!
    4. Re:Advocacy, we never knew thee. by swillden · · Score: 3, Informative

      a ^= b ^= a ^= b;

      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.

      Bull.

      It's an overly clever hack that doesn't belong in a professional product. Why? Four reasons:

      1. Speed: It is not fast. It's far slower than the typical:
        c=a;
        a=b;
        b=c;
        Don't believe me? Grab a compiler, compile to assembler and check it out.
      2. Storage: It requires exactly the same amount of storage, since the temp will always be in a register anyway (and the same register is required to store the result of computing a^b). Again, if you don't believe me, compile both to assembler and check 'em out.
      3. Correctness: The line as written is *wrong*. It may work with some compilers, but the C and C++ standards both say that the result of the line is *undefined*. Why? You can't apply multiple operations including assignments to the same variables without an intervening sequence point (which, usually, means a semi-colon). The following is correct, although still slower than using an explicit temp:
        a ^= b;
        b ^= a;
        a ^= b;
      4. Clarity: It is not immediately intuitive to anyone. Anyone who has seen the "cool hack" somewhere else will probably recognize it, true, but the use of a temp, or, even better, the use of std::swap() are guaranteed to be understandable at a glance. And there is no real, educational reason why anyone *should* have seen this hack, since it's really not useful.

      The "comparison" article is poor at best, but in this aspect it is 100% correct. XOR-swapping is a cool hack but has no redeeming values other than its coolness, and cleverness for its own sake has no place in professional code.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    5. Re:Advocacy, we never knew thee. by spongman · · Score: 2

      Don is wrong. The IDEs for Visual C++ (versions 2 through 6) were all MFC apps. In fact, the original creators of MFC were the ones that wrote the 'new' shell for VC2.0 (the one with the dockable windows). The Doc/View architecture of MFC was derived from the framework for an unreleased product codenamed Sequioa that was destined to become VC2.0, but which was canned in '92 to free resources for shipping VC1.0. I believe PictureIt! was also an MFC app, as is WordPad.

    6. Re:Advocacy, we never knew thee. by CoolVibe · · Score: 2

      I did some tests:

      sh-2.05a$ ./swapbench
      xorswapping 10 secs: 6999572 iterations
      tmpswapping 10 secs: 7785816 iterations


      The code for this is here. I know it's not really a representative benchmark, but it does show the point somewhat. And yes, using a temp variable is hella faster.

    7. Re:Advocacy, we never knew thee. by Ben+Hutchings · · Score: 2

      Microsoft used MFC quite a lot, mostly in their developer products (AFAICS). If you go to the Microsoft DLL information pages and enter the filename of a DLL you'll get a list of released versions; then by selecting "More Information" you can get a list of products that included that version. For MFC, try filenames mfc30.dll, mfc40.dll and mfc42.dll. Many versions of Windows include MFC, perhaps to support programs like WordPad. Various other products include an updated version of one of these DLLs.

    8. Re:Advocacy, we never knew thee. by sir99 · · Score: 2
      Please pardon my sloppy HTML.

      1. Well, that depends on your compiler. Testing with gcc 3.1 with -O3, I found that gcc has a special optimization for the standard swap construct (I also tried using the Intel compiler, but it produced nasty code that I had no desire to dissect). It assembles to something like this, where the bold variables are registers, and the others live in memory:
        ax = a; //read
        bx = b; //read
        a = bx; //write
        b = ax; //write

        This code has 2 memory reads and 2 writes, whereas the xor construct assembles to a monstrosity with far more memory access than necessary. So yes, on gcc the normal swap is much faster, but a well-assembled xor construct, with just the 4 required memory accesses, would probably only be a few cycles slower, rather than a few hundred. The memory accesses contribute the great bulk of time consumed.
      2. You're not quite right here. Most assembly operations are like operation= in C. There is no temporary register used to store the result of a^b, because the operation is done in hardware as a^=b. You're right in this case that they both use the same amount of storage, but that's only because gcc recognized a common construct and optimized it.
      3. No comment.
      4. It's almost intuitive to people who have learned assembly, but probably not to anyone else. In fact, in light of gcc's particular quirks, hand-written assembly, where the variables are already in registers, is probably the only place xor-swapping should be used. It may be an advantage there, because it only uses two registers instead of three for the normal swap, and on x86, registers are at a premium.
      --
      The ocean parts and the meteors come down
      Laid out in amber, baby.
    9. Re:Advocacy, we never knew thee. by swillden · · Score: 2
      1. That's precisely the code gcc should emit, and that's what every decent C compiler I've used in the last 12 years has emitted. I don't think it's so much that they recognize the swap construct as the optimizer sees a simple and obvious optimization. Try writing the unoptimized code and look at it as though you had no idea what the original C code said: you'll find the optimization is still obvious.
      2. In fact, I was wrong, for the obscure reason that I had forgotten the x86 has no memory to memory variant of mov, which means that the standard approach does require one more register than the XOR version. Here, to make confusion impossible, consider the following (comments show timings for 386/486 processors -- sorry, only manuals I have handy).

        Standard version

        mov ax, [a] ; 4/1
        mov bx, [b] ; 4/1
        mov [a], bx ; 2/1
        mov [b], ax ; 2/1

        Total: 386: 12 cycles, 486: 4 cycles.

        XOR version

        mov ax, [a] ; 4/1
        mov bx, [b] ; 4/1
        xor ax, [b] ; 2/1
        xor [b], ax ; 6/3
        xor ax, [b] ; 2/1
        mov [a], ax; 2/1

        Total: 386: 20 cycles, 486: 8 cycles

        The XOR approach does have the advantage that it requires only one register, but it consumes so many more cycles that it would still be faster to add a pair of mov instructions to save and restore the contents of bx and then use the standard approach. This would bring the total timings of the standard approach up to 18/6.

      3. This was actually my most important point. A compiler is free (and not unlikely) to emit code that is uses the original values of a and b in every step of the process, which will probably be boiled down by the optimizer to:
        mov ax, [b]
        xor [a], ax

        Now, of course that would certainly be *efficient*....

      4. You almost make a good point here. If a and b are already in ax and bx, respectively, then the XOR swap can be done without involving another register.
        mov cx, ax ; 2/1
        mov ax, bx ; 2/1
        mov bx, cx ; 2/1
        vs.
        xor ax, bx ; 2/1
        xor bx, ax ; 2/1
        xor ax, bx ; 2/1

        So, identical performance (on these processors) but one less register. Here, the XOR swap is a win. It would be a win even if it took a few more clock cycles.

        Now for the explanation of the "almost": Swapping the contents of two general-purpose registers is completely stupid. Instead, the compiler should "mentally relabel" the two registers and go on about its business. Now, some x86 registers all do have special meanings with respect to some of the higher-level instructions, but swapping values around to prepare for execution of, e.g. a REP instruction is something that the C programmer should never even dream of being concerned about.

      I see no realistic situation on any platform I'm familiar with where XOR swapping is a performance win over standard swapping. That's not to say it isn't a win somewhere on some platform, but choosing to write C code that XOR-swaps is a bad idea, because most of the time you won't end up with a better result and you will probably confuse the poor bastard who has to maintain your code later.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    10. Re:Advocacy, we never knew thee. by swillden · · Score: 2
      Been There, Done That ;-)

      And, yeah, I know the x86 registers aren't completely general purpose, which is why I mentioned the REP instruction. I do agree that the cool hack is occasionally useful for assembler programmers who need to swap a pair of regs to set up some other instruction but don't want to use another register.

      I, myself, was never clever enough to use it that way, so I learned something here, too. Not that I expect to write much assembler these days; compilers are too good and processors, non-embedded processors at least, are too fast and too danged complicated for hand-optimized assembler to be cost-effective anymore... more's the pity, that stuff is fun.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  7. Re:Create() and exceptions by Curien · · Score: 2

    Ummm... no. Qt may or may not report errors via C++'s exception mechanism, I don't know. But insinuating that exceptions are the *only* way to report errors encountered during a ctor is patently false. For a counter-example, one need look no further than the standard IOStream library:

    #include <iostream>
    #include <fstream>
    #include <cstdlib>

    int main() {
    std::ifstream file("file.txt");
    if(!file) { // look ma, no try block!
    std::cerr << "file.txt could not be opened for reading.\n";
    return EXIT_FAILURE;
    }
    return 0;
    }

    --
    It's always a long day... 86400 doesn't fit into a short.
  8. MSDN by Screaming+Lunatic · · Score: 2

    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.

    1. Re:MSDN by Dalroth · · Score: 2

      No way, MSDN is terrible. All the information is there (if you can find it), but it's highly scatterbrained and disorganized. Half of the usefull information is locked up in the Knowledge base which is just a listing of sequential articles with no organization to it at all (you have to SEARCH for everything).

      If you compare the API defintions of one API (say ADO) to the API definitions of another (say RegExps) the API documentation is often in COMPLETELY different formats, and we won't even talk about where some of those API docs are located.

      The API documentations frequently don't explain what parameters are supposed to (or allowed to) contain, and even if they do their frequently listed on a seperate page without any explanation of the meanings for the various values.

      Oh, and good, standardised documentation about those COM/COM+ error codes located in a single and easily accessible location? Forget.

      I hate to rant here, but I've been dealing with MSDN's limitations for well over 6 years now and it's hardly better now than it was 6 years ago.

      In all honesty, I can find the solution to my problem 10x faster by going straight to groups.google.com. I find information in the MSDN archive quicker from groups.google.com than I ever do searching for it directly.

      SUN's Java documentation is an example of how things should be documented. It's not perfect, but it's 1000x better than what MSDN offers.

  9. Development tools? by allanj · · Score: 4, Insightful

    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
  10. Oreos or chocolate chip? by Curien · · Score: 2

    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.
  11. Qt vs .NET? by ClosedSource · · Score: 2, Insightful

    I don't think there are many Windows programmers using MFC for new development. A comparison of Qt and .NET would be more relevant.

    1. Re:Qt vs .NET? by Anonymous+Brave+Guy · · Score: 2
      I don't think there are many Windows programmers using MFC for new development.

      That's an interesting perspective. Personally, I don't think there are many Windows programmers using .NET for new development.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:Qt vs .NET? by Anonymous+Brave+Guy · · Score: 2
      "Personally, I don't think there are many Windows programmers using .NET for new development"
      Well, I can't prove that there are, but there were about 5000 programmers who traveled to Orlando back in July of 2000 to learn about .NET (and paid a lot of money to be there). So, I think there is some evidence of interest.

      Sorry, I couldn't resist the cynical one-liner. In all seriousness, though, I think .NET is much hyped but, so far at least, little used. There are always those who will go with whatever Microsoft produces. They went for Visual Basic first, they went for COM first, and they'll got for .NET and C# first. The remainder of the Windows programming world -- the vast majority -- is more interested in making a product and getting paid for it, and will therefore probably stick with tried and tested solutions like VB6, VC++6 w/ MFC, and so on for a long time to come.

      Microsoft is trying the same trick with the programming world that it's attempted with Windows and Office users recently: produce a new version, with limited new features applicable to a few users only, and hope the bigger version number and hype is enough to get everyone else moving as well. It hasn't worked well so far with office users, and I doubt the programming world (for all their natural instincts to use the latest and greatest) will be any more easily fooled.

      To give credit where it is due, .NET does seem to offer genuine advantages for those writing certain types of application, notably anyone interested in web services. (I don't know why anyone would write for it in "Managed C++", though; if you're doing new development for .NET, you might as well use C# or VB.NET so you can take advantage of it cleanly.) For the average desktop application, though, .NET seems to offer little other than a whole new class library to learn and a whole new massive overhead to install.

      You're right that anyone programming for Windows should probably consider it in their own circumstances, of course. I spent quite some time looking into it during the months running up to its release, from the point of view of writing a typical desktop Windows application. I found no compelling reason to move to the new technology, with all the retraining and redevelopment of libraries and tools that necessarily requires.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    3. Re:Qt vs .NET? by Ben+Hutchings · · Score: 2

      Most of those people were getting a trip to Orlando at someone else's expense. I probably wouldn't mind doing that whether or not I was interested in .NET.

  12. MFC not *that* bad by RailGunner · · Score: 2
    The author's right, QT is far superior to MFC. Cross platform support and a nice, easy to use slot / signal architecture makes my life as an application developer much easier.

    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?

  13. Great, if this was 2-8 years ago... by malakai · · Score: 2

    (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.

  14. MFC is NOT replaced by Windows Form by edyu · · Score: 3, Informative

    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:

    It has been three years since the last major update to MFC and ATL. With all the press on Microsoft® .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.

    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.

  15. Re:Create() and exceptions by Curien · · Score: 2

    If ::new fails then it will throw, sure. But the object is free to catch std::bad_alloc inside the ctor and transpose it onto some other error-reporting schema. Just because something *in* the ctor throws, doesn't mean that the ctor has to propogate the exception.

    As far as ifstream is concerned, you can't tell *why* the file couldn't be opened because ifstream is abstracted that way. You could easily have some sort of "error state" (similar to badbit, eofbit, and failbit) which can be reported to the client only when the client asks for it. Simplest way I can think of to do that is with a get_last_error() member function that simply returns the error code of the last operation the object performed.

    Sure, exceptions can be helpful in RAII, but they are by no means required by it. To assume so is not only incorrect, it diminishes C++'s lack of paradigm bias.

    The only time I can think of when you're *forced* to propogate exceptions is when you have a polymorphic class whose base class's ctor throws. But then, you made a design decision to inherit from a class that throws.

    --
    It's always a long day... 86400 doesn't fit into a short.
  16. Re:Create() and exceptions by Anonymous+Brave+Guy · · Score: 2
    The only time I can think of when you're *forced* to propogate exceptions is when you have a polymorphic class whose base class's ctor throws.

    Any subobject (base class or data member) that throws during construction will result in the object itself failing with an exception. You can wrap the c-tor's initialiser list in a function try-block if your compiler supports it, but that only allows you to change the type of exception thrown, not the fact that some exception is thrown. If you think about it, that's the only model that makes sense, and it's also very clean and tidy.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  17. Re:Create() and exceptions by Curien · · Score: 2

    Yes, that's the only way the object model can make sense *if you're containing actual objects*. You can easily get around that by changing the contained object(s) to a contained pointer to object. Same goes for private inheritance: change it to a contained pointer to object. If all your after is interface inheritance w/o polymorphism, just use a contained pointer plus forwarding functions. Like I said before, the only time you're *forced* to propogate exceptions from a ctor is when a polymorphic base class's ctor throws.

    --
    It's always a long day... 86400 doesn't fit into a short.
  18. A bit *too* nice about Qt by Anonymous+Brave+Guy · · Score: 3, Insightful

    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.
    1. Re:A bit *too* nice about Qt by Anonymous+Brave+Guy · · Score: 3, Informative
      These are well-known design flaws with both approaches, relating to efficiency, thread safety, etc.
      In 3 years of development with Qt, I haven't met any of the problems you describe. Maybe I am not writing the right programs.

      Maybe you've been lucky. Who knows? The fact remains that there are demonstrated problems that can occur when using COW strings in a multithreaded C++ system, and further, the advantages of using such a design are mostly illusory anyway. It seemed like a good idea at the time, but on reflection, it turned out not to be. (BTW, I have watched an application fall over for no good reason because its string library wasn't multithread-safe when it should have been, and I've watched the development team waste several man-days of time trying to find the bug in their code -- which wasn't.)

      If they wanted an improvement, they should have provided an immutable string class with a suitable set of operations,
      You mean a QConstString

      I don't think so. I mean a full-fledged immutable string class that supports the usual look-up and combination operations without the mutating ones, and a clean interface to convert between such a class and a vanilla QString. AFAICS, that's a whole world away from QConstString.

      You can [lay out dialog controls in exact positions] if you want, even with Qt Designer. But I don't see when you want to do that. Could you give an example ?

      In simple cases, I agree, an automatic layout can be very helpful. OTOH, on a program I used to work on, extensive used was made of tabbed dialogs. The layouts of most of them were fixed across all of the tabs, so that similar controls didn't jump around irritatingly as you flipped from tab to tab. I don't know if Qt's automatic layout system would handle that, but certainly no other one I've ever seen does. Automatic layout is simply not the best answer to everything, which the article seemed to be suggesting.

      A simple tr() function is not the silver bullet here, contrary to what the article seems to suggest.
      Yes it is. gettext() had it right from years. This approach allow the developer not to worry too much about translation, allow the translator not to cope with compiling stuff and get automatic update, and allow the user to add new language without hassle and to switch easily from one language to another.

      With all due respect, if you think a simple translation mechanism like that is all there is to i18n/l10n, I can't believe you've ever worked on a large-scale multi-lingual application. There are other locale-related formatting issues (date/time, currency, etc). There are languages where routine system calls don't work on some strings (try a toupper on the German word Strasse, and then try the same on the same word written with a Schaffes s, and then compare them for equality). In Japan, most machines speak MBCS, not Unicode, so you need an effective means of converting between them, preferably as soon as the MBCS enters your program and just before it leaves so you can at least use Unicode internally. Some languages read right-to-left, or top-to-bottom, or even more devious variations, and you have to adapt your UI to cope with this, particularly when laying out dialog boxes and such. It is not as simple as a tr() function. (I'm not saying Qt couldn't cope with many of these issues, just that the emphasis placed on the tr() function by the article is overstated.)

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:A bit *too* nice about Qt by Anonymous+Brave+Guy · · Score: 2

      Sorry, didn't mean to come across as bashing Qt. I realise it was first created pre-standard and couldn't have benefitted from the experience gained by the C++ community over the past five or so years. I was trying to highlight flaws in the evangelism of the original article by citing obvious concrete examples of false claims (containers better than STL, yada yada).

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    3. Re:A bit *too* nice about Qt by Ben+Hutchings · · Score: 2
      A simple tr() function is not the silver bullet here, contrary to what the article seems to suggest.

      Yes it is. gettext() had it right from years. This approach allow the developer not to worry too much about translation, allow the translator not to cope with compiling stuff and get automatic update, and allow the user to add new language without hassle and to switch easily from one language to another.

      A major problem with gettext() is that there can only be one translation of each of the strings in the original language. What happens when you use an English word with different meanings in different contexts, that should be translated to separate words in another languages? Usually your messages will be long enough that this doesn't happen, but in a GUI you may well use text labels with only one word in them.

    4. Re:A bit *too* nice about Qt by infiniti99 · · Score: 2

      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.

      Can you explain these inefficiencies, or provide a URL to some analysis about them? Personally, I think the copy-on-write stuff is really cool. Not just QString, but even container classes like QValueList won't duplicate your objects unless needed. Native Unicode makes things simpler too...

  19. Re:Create() and exceptions by Anonymous+Brave+Guy · · Score: 2

    I think what you're trying to say is that if you don't want to allow a constructor to fail, you can change your design so that you can trap the exception that would be thrown by a base class or data member under normal circumstances. That's not what you actually said, though.

    Of course, whether you want to have a design that carefully works around a system that's there for your own good is another question. Most of the time I've seen designs that went out of their way to ignore exceptions in a system that used them, the design was broken. Two-stage construction with Create() and Destroy() methods is a Bad Thing(TM) under almost all circumstances, and is responsible for more programming bugs in C++ than almost anything else I've come across (apart from naff use of pointers and arrays when smart pointers and container classes were the right tools for the job, of course).

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  20. New != better by Anonymous+Brave+Guy · · Score: 2
    Anyone creating an app from scratch right now, or porting an app not written in MFC, should _not_ be even considering MFC.

    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?

    .NET has precious little in the way of genuine benefit to offer most projects. Its class library isn't much better than MFC in many places, and it introduces a whole new range of limitations and bugs that people will have to learn to work around (if they can). Please don't shout "garbage collection!" or "class library!" at me, because it will cut no ice. The use of either limits you so seriously that you might as well give up all the good things about C++ and other libraries available for it and use C# instead; "managed C++" isn't really C++ at all.

    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.
  21. Don Box by Anonymous+Brave+Guy · · Score: 2
    According to Don Box (COM guy, now works at Microsoft) the number is 0 - zero! nil! (He mentioned it in his keynote address at Microsoft Developer Days 2001 in Copenhagen)

    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.
  22. MFC by oliverthered · · Score: 2

    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.
  23. Kylix 3 just released with c++ and OP by oliverthered · · Score: 2

    borland has Just released Kylix 3with C++ and Object Pascal support in one product.

    Don't know why this hasn't made it to /. yet?

    --
    thank God the internet isn't a human right.
  24. HTML help is EVIL by oliverthered · · Score: 2

    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.
  25. Re:Create() and exceptions by Curien · · Score: 2

    Sort of, but not quite. It's not a *design* change, it's an *implementation* change. Big difference. My only exception (polymorphic base class ctor throws) is the only situation where avoiding a throw in the ctor would actually require a design change.

    I think we're pretty much in agreement, though. Don't know why anyone would go through all that trouble just to avoid a try block anyway.

    --
    It's always a long day... 86400 doesn't fit into a short.
  26. Re:Create() and exceptions by Anonymous+Brave+Guy · · Score: 2

    OK, fair point, your change is implementation rather than design. And yes, we agree; exceptions and try-blocks are there for a reason, and it's usually easier to use them as they were intended than to fight against them.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  27. Arcane trivia by GCP · · Score: 2

    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."
  28. Visuial studio by oliverthered · · Score: 2

    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.
  29. Problems with string classes by Anonymous+Brave+Guy · · Score: 2

    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.
  30. QT and moc by heroine · · Score: 2

    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.