Embedded QT window controls in the MFC&QT Mixed programming part1 MFC dialog box

Source: Internet
Author: User
Tags mixed

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.