See a written article about MFC and QT mixed programming, Mark, turn from
http://blog.csdn.net/sinat_24206709/article/details/77185974
Embedded QT window controls in the MFC&QT Mixed programming part1 MFC dialog box
1. Environment configuration: vs2010,qt4.8.4_win64,qt_vs_addin_1.1.11
2, create the MFC dialog box program
3, the output for the x64 Debug&release program
Preparatory work:
Download qtmigration file
http://download.csdn.net/download/power_YQ/3539936
First step:
Create one of the simplest MFC Dialog Programs--compilation should be a normal MFC program.
Step two:.
1. Add Qmfcapp qwinhost qwinwidget six corresponding. h. cpp files in the downloaded source file to the project
2, add the corresponding QT header file: include include "Qmfcapp.h" include "qwinhost.h" include " qwinwidget.h"
3. Add one line of code to the BOOL ctestapp::initinstance () function:
Qmfcapp::instance (this);
The ability to trace the static function clearly to the Qmfcapp code is to create a qapplication instance.
Step Three:
Rewrite the Ctestapp Run method--Add virtual int run () to the header file;
The functions in the CPP are as follows:
int Ctestapp::run ()
{
int result = Qmfcapp::run (this);
Delete Qapp;
return result;
}
Note--QT Help Introduction:
Qmfcapp:run ()
Would then use this qmfcapp::instance, which must then be deleted using the global explicitly qapp.
Fourth Step:
Add a definition to the TestDlg.h file--Note the header file to add QT:
Qwinwidget *widget;
Fifth Step:
1, in the project right click-Class Wizard-class name to correspond to testdialog this class--to the left below the Message tab box--Double click to select Wm_create and wm_destory--determine
2, add the following code in the Ctestdialog oncreate function:
Widget = new Qwinwidget (this);
Qhboxlayout *hbox = new Qhboxlayout (widget);
Qlabel *label = new Qlabel ("Enter text:", widget);
Qlineedit *edit = new Qlineedit (widget);
Hbox->addwidget (label);
Hbox->addwidget (edit);
Widget->move (0, 0);
Widget->show ();
Note: Remember to add the corresponding header file or QT declaration: include "Qwinwidget.h" include include include include