Important: Please read the Qt Code of Conduct -

What is the advantage & disadvantage of Qt's signal-slot mechanism compared to MFC's message mechanism?

  • what is the advantage & disadvantage of Qt's signal-slot mechanism compared to MFC's message mechanism?
    is there anything which Qt can do but MFC can't?
    or Qt can easily realize but MFC is very hard?
    Meanwhile, the efficience problem, which one is more efficient on Windows?
    thank you very much

  • anyone help? :D

  • Moderators

    I suspect no one is willing to answer this because the questions you ask are very broad and many answers would be purely opinion based.

    I don't know MFC that well, but for what I do I can offer few biased points in Qt favor:

    • signal/slot mechanism is dynamic i.e. you can connect and disconnect at runtime while (from what I understand) MFC messages are "static" i.e. defined as macro blocks and "connections" are evaluated at compile time.
    • As a result of above MFC messages are "targeted" i.e. the object posting a message needs to specify a receiver. Qt model on the other hand is subscription based. An object sends a signal and doesn't care who responds to it. Any other object can. This is IMO more flexible.
    • Similar is true in threading contexts. In MFC you need to post a message to a known thread object, while in Qt you don't even need to consider there are threads. The synchronization will be done for you automatically when you connect objects in different threads.

    All in all I think Qt is easier to work with and more dynamic. As to performance I can't say. I haven't seen or done any comparisons, but it would certainly be interesting to see some.

    Some less to the point arguments:

    • Qt is portable, MFC is Windows desktop specific
    • Qt is actively developed and opensourced while MFC is slowly bleeding to death and has mostly just bug fixes these days
    • In my opinion the amount of macro spew in MFC is ridiculous. Of course if you like macros this is a null-argument
    • Qt designer is sooo much nicer to work with than MFC form editor ;)

  • yeh, thank you very much.
    i know it's hard to compare Qt with MFC
    However, my question here is compare their Message Mechanism :D

  • Hi,

    If you onyl compare the message mechanism, you have it in both. Windows message loop in MFC and Qts event loop.
    I know both ways, and what I can say is Qt is a easier, better to understand (Class based messages) and easier to maintain. You have more options (event filter, ...).

    But Qts signal/slot mechanism is something different than MFCs (Windows) message mechanism. Signals and slots make object interactions, windows messages are not. You can use them that way, but it's not the standard way.

    Qts signal/slot work inter-thread, are thread save, can be used synchronously and asynchronously, etc. You can specify any type of parameters, POD or classes, and they are cleaned up. You can connect to signals which have more parameters, unless the ones you have in your slot exist in the signal also, and so on.

    By the way, I have never seen performance problems here...

  • very complete interpretation.
    thanks a lot:)

Log in to reply