Migrate from MFC visual studio 2008 to Qt5
-
Currently all our GUI components are written in MFC with visual studio 9.0 .I have no idea whether: 1) We can replace all MFC components with Qt, without changing build environment ? You answers will help me in getting started, In the mean time I have installed Qt 5 and am trying to migrate from MFC to Qt5.
-
@willkom said in Migrate from MFC visual studio 2008 to Qt5:
Currently all our GUI components are written in MFC with visual studio 9.0 .I have no idea whether: 1) We can replace all MFC components with Qt, without changing build environment ? You answers will help me in getting started, In the mean time I have installed Qt 5 and am trying to migrate from MFC to Qt5.
Since you copied the question from https://stackoverflow.com/questions/1700428/transition-from-mfc-to-qt, you can copy the answer too
-
@willkom said in Migrate from MFC visual studio 2008 to Qt5:
cannot find the following files "afxwin.h", "afx.h"
Those headers are part of an external library, so you must add the library to your project. I presume you are using the Qt Creator IDE? If so, follow these steps to add external libraries to your Qt project: https://doc.qt.io/qtcreator/creator-project-qmake-libraries.html
Alternatively, you can use the Qt Visual Studio Add-In to use Qt libraries in Visual Studio: https://marketplace.visualstudio.com/items?itemName=TheQtCompany.QtVisualStudioTools-19123
-
@JKSH thank for your answer but i don't wan to use Visual Studio and MFC anymore i wan to import all my MFC Visual studio projects in Qr Creator.
i added all the necessary libraries, but that generated a lot of errors, it look like MFC framework only work in visual studio. -
@willkom
If you don't want to use MFC any more why are you trying to import them into Creator? Can't you pull your own code across and start editing it to move away from MFC without needing to get MFC working, which is going to be a hassle? -
@willkom said in Migrate from MFC visual studio 2008 to Qt5:
it is possible to set Qt creator to use MSVC++ compiler ?
Yes it is. Install Qt for MSVC first.
-
Do you really expect to get a recent Qt version for a compiler which is more than 13 years old?
-
Mixing MFC and Qt can be done. I'm doing it right now. But I'm using Visual Studio with the Qt Extension not Qt Creator. Getting it to work requires a bit of a "hack". You have to include a CWinApp class with an InitInstance() function and call that from the main() function in main.cpp. Also you can't intermix MFC controls and Qt controls in a single dialog. You can only use separate MFC or Qt dialogs that are contained in their own classes. I'm only doing this because I have some MFC based classes that I need to use during development and I'm not ready to port over to pure Qt just yet. However the ultimate goal is to port the entire project to Qt. But it's a big project with millions of lines of code so I'm porting it piece by piece.
-
@willkom
Again: if you state your goal is to migrate away from MFC to Qt, why are you trying to constrain your environment (compiler) to get the MFC working with Qt? Wouldn't it be simpler not to try to do so and just pick a new Qt/compiler environment and migrate across? I just don't get it.... -
@willkom Before you start migrating your project from MFC to Qt I would suggest to migrate from VS 9.0 to something modern, preferably VS2019. This alone will be a big task, so don't pile problems up and start with that. When you finish that you can start porting to Qt5 using the qtwinmigrate library. After that you can think of migrating to Qt6 if there's something interesting in it for you.
There's no point switching to Qt still using VS 9.0. Qt5 does not support it (it won't even compile). The last Qt version to support it was 4.8 (I think), which is ancient at this point and already obsolete, so there's little benefit in switching to that.
@Dan203 said:
Also you can't intermix MFC controls and Qt controls in a single dialog
Well that's not entirely true. You can embed Qt widgets inside native MFC windows and the other way around. I've done it and it works. It's a Frankenstein's monster and a pain in the rear to get the event delivery and focus switching right but it's doable. I'm in the same boat as you - giant project that took years to port piece by piece, so had to develop entire "framework" to allow that mixing but it's doable.
-
@JonB In my case the project is big and migrating everything at once simply isn't feasible. Even if I wanted to do that I'd still need to link against MFC temporarily just for testing. If I didn't link MFC at all then I wouldn't even be able to debug my code until the entire project was ported, which would be essentially impossible.
-
@willkom: To summarize the advice from @Dan203 and @Chris-Kawa, you should do the migration in multiple steps:
- First, port your project from Visual Studio 2008 to Visual Studio 2019
- Then, install Qt 5 for MSVC 2019
- Then, build the qtwinmigrate framework to use with your project: https://github.com/qtproject/qt-solutions/tree/master/qtwinmigrate
-
Thank you everyone.
@Chris-Kawa do I have to use the qtwinmigrate library? I just can't use the msvc_2019 compiler in qt creator 5? -
@willkom said in Migrate from MFC visual studio 2008 to Qt5:
I just can't use the msvc_2019 compiler in qt creator 5?
Of course you can. You can't use MSVC 2008...
-
@willkom said:
do I have to use the qtwinmigrate library? I just can't use the msvc_2019 compiler in qt creator 5?
One has nothing to do with the other. You need to update VS to be able to use Qt5. There's no Qt Creator 5. There's Qt5 and Qt Creator is an IDE (a program made with Qt).
qtwinmigrate is unrelated and is just a convenience library that helps with the complicated embedding and event routing between MFC and Qt but you don't have to use it if you don't want to. You can do everything it does manually. It's just more work.
-
@Chris-Kawa, so using qtwinmigrate library mean convert all the MFC dependency of the project to Qt5 dependency right?