Integrating Qt in legacy MFC applications

by Carlos Buchart (STT Systems)

Abstract

Many Windows desktop applications written in C++ rely on MFC for the user interface. Compared to MFC, Qt offers a set of more modern tools to develop GUI applications, such as more intuitive and straightforward API, better integration with modern C++, UI designer and localization tools. Nevertheless, migrating this existing (and usually large) code base takes a lot of time, and limited team resources may lead to delay the transition and, therefore, to take advantage of many of the modern Qt features, especially those related to the UX. In this line, while some Qt’s modules can be integrated seamlessly, others offer more problems. This is the case of UI-related modules, that present incompatibilities with the MFC core (for example, QDialog is not modal for the MFC application).

This is the case of capture movement and analysis systems at STT Systems, where some of the core applications have been developed since 1998, intensively using MFC, and in 2014 we started the incorporation of Qt as our main framework.

This session will cover our experience in using Qt in legacy projects (more specifically MFC applications). First, we will focus on how you can integrate new modules made using Qt into the existing MFC workflow, given a few constraints that can be removed once the migration is completed. Regarding the GUI, we will discuss how to mix both MFC and Qt interfaces (Qt Widgets) and how to deal with modal Qt dialogs in the MFC events loop. Finally, some words will be said regarding the opposite direction: using existing MFC modules in a Qt application, limitations and considerations.

All these techniques are widely used in the development of end-user applications at STT Systems, and they will be taken as examples to show the different cases exposed and how we managed to mix MFC and Qt, while moving forward our end goal of having all of our code using Qt.