Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Migrating from MFC to Qt

1,258 views

Published on

Ievgen Krasilnyk Senior Software Engineer in GlobalLogic Kharkiv with 9+ years of broad experience in C++ development, including over 5 years of cross-platform applications development using the Qt framework.

During the talk, Ievgen Krasilnyk presented how to set up the environment and conversation for an MFC project, create a modal dialogue using QWinWidget, and integrate QWinWidget into the mechanism of MFC docking.

This presentation by Ievgen Krasilnyk was delivered at GlobalLogic Kharkiv C++ TechTalk #3 on March 26, 2019.

Video: https://youtu.be/PUEzsb2CGFg

Published in: Technology
  • Be the first to comment

Migrating from MFC to Qt

  1. 1. 1 Migrating from MFC to Qt Ievgen Krasilnyk Senior Software Engineer, Engineering
  2. 2. 2 Agenda 1. Setting up the environment and converting of MFC project 2. Creation of the modal dialog with the help of QWinWidget 3. Integration of QWidget into the mechanism of MFC docking
  3. 3. 3 Terminology • MFC - Microsoft Foundation Class Library • WPF - Windows Presentation Foundation • GUI - Graphical User Interface • API - Application Programming Interface • COM - Component Object Model • IDE - Integrated Development Environment
  4. 4. 4 Confidential 4 Why Do We Need to Change Something ? • MFC was introduced by Microsoft in 1992 • Is wrapper over Win32 and COM APIs • Most applications GUI for Windows is based on WinForms/WPF • Poor toolkit
  5. 5. 5 Confidential 5 What Are the Options ? • BCGControlBar Professional Edition for MFC • wxWidgets cross-platform GUI library • Qt software development framework
  6. 6. 6 wxWidgets 3.0.4 • Basic Windows - 6 • Window Layout - 9 • Managed Windows - 10 • Menus - 3 • Controls - 52 • Validators - 5 • Picker Controls - 5 • Miscellaneous Windows - 25 • Windows Docking - 5 • Common Dialogs - 19 • HTML - 8 Number of classes in modules • Device Context - 13 • Graphics Context - 7 • Graphics Device Interface - 11 • Image and Bitmap - 11 • Events - 50 40 modules Total 432 classes
  7. 7. 7 Qt 5.12 • QtQuickWidgets - 1 • Qt3DCore – 36 • Qt3DAnimation – 24 • Qt3DExtras – 26 • Qt3DInput – 25 • Qt3DLogic – 2 • Qt3DRender – 109 • Qt3DScene2D – 1 • QAxContainer – 7 • QAxServer – 3 • QtAndroid – 9 Number of classes in modules • QtConcurrent - 1 • QtCore – 242 • QtGui – 226 • QtNetwork – 50 • QtWidgets - 200 58 modules Only Core + Gui + Widgets > 600 classes
  8. 8. 8 Confidential 8 Setting up the environment and converting of MFC project
  9. 9. 9 Confidential 9 Setting Up Environment • Download and install Qt • Install Qt Visual Studio Tools • Set up default Qt version
  10. 10. 10 Create New MFC Application
  11. 11. 11 Create New MFC Application
  12. 12. 12 Convert to “Visual Studio Qt Project” <PropertyGroup Label="Globals"> <ProjectGuid>{6022B543-E927-4531-B299- E1F56C47CBFD}</ProjectGuid> <RootNamespace>MFCApplication_example</RootNamespace> <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> <Keyword>Qt4VSv1.0</Keyword> </PropertyGroup>
  13. 13. 13 Change Project Settings • C++ -> General -> Additional Include Directories : $(QTDIR)include • Linker -> General -> Additional Library Directories: $(QTDIR)lib • Qt Project Settings: Core, GUI, Widgets • Now you are almost ready to go
  14. 14. 14 But Wait a Minute
  15. 15. 1515 Confidential Creation of the modal dialog with the help of QWinWidget
  16. 16. 16 Confidential 16 Qt/MFC Migration Framework • Download QtSolutions from github • Configure and build using instructions (Readme.txt) • Can be built with IDE using a *.pro file
  17. 17. 17 Last Time, I promise • C++ -> General -> Additional Include Directories: qtwinmigratesrc • Linker -> General -> Additional Library Directories: qtwinmigratelib • Linker - >Input -> Additional Dependencies: QtSolutions_MFCMigrationFramework-headd.lib • Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions: QT_QTWINMIGRATE_IMPORT
  18. 18. 18 Run QApplication Inside of MFC Application • Use QMfcApp class to run QApplication inside of MFC Application • Call QMfcApp::instance(this) in CMFCApplicationApp::InitInstance() • Call QMfcApp::run(this) in CMFCApplicationApp::Run() • Use QCoreApplication::setApplicationName() and QCoreApplication:: setOrganizationName() to be able to use QSettings
  19. 19. 19 Creating Modal Dialog Using QWinWidget • Override CMFCApplicationApp::OnAppAbout() • Use QWinWidget class to pass m_pMainWnd as a parent • Call QDialog::exec() to show modal dialog
  20. 20. 20 Confidential 20 Integration of QWidget into the mechanism of MFC docking
  21. 21. 21 Using QWidget Inside of MFC Dock Window • Create dock replacement class based on CDockablePane • Override protected method CDockablePane::OnCreate() • Override protected method CDockablePane::OnSize() • Use QWidget and QWinWidget as members • Initialize widgets in CDockablePane::OnCreate() method • Resize widgets in CDockablePane::OnSize() method • Add replacement class as CMainFrame’s member • Make changes in CMainFrame::OnCreate() • Make changes in CMainFrame::CreateDockingWindows() • Make changes in CMainFrame::SetDockingWindowIcons()
  22. 22. 22 Confidential 22 Links And Sources • https://github.com/qtproject/qt-solutions • https://stackoverflow.com • https://www.wikipedia.org • https://msdn.microsoft.com • https://www.qt.io • https://www.wxwidgets.org
  23. 23. 23 Ievgen Krasilnyk Senior Software Engineer, Engineering Ievgen.krasilnyk@globallogic.com Thanks for Attention!

×