Mixed MFC and QT programming-use QT components in the MFC Program

Source: Internet
Author: User
Copyright Notice

Respect Original Works. Reprinted, please maintain the integrity of the article, and in the form of a hyperlink to indicate the original author "tingsking18" and the main site address, so that other friends can ask and correct.

 

 

Mixed MFC and QT programming-use QT components in the MFC Program

1. Create a simpleMFC DialogProgram.

2. InBool ctestapp: initinstance ()Add to function
Qmfcapp: instance (this );

Tracking qmfcapp
The function of the static function is to create a qapplication.
Instance.

 3.
 Override the run method of ctestapp.
As follows:
int CTestApp::Run() {       int result = QMfcApp::run(this);    delete qApp;    return result;}
I am not sure what it means.
Qt help:
QMfcApp:run() will then use that QMfcApp::instance, which must then be deleted explicitly using the global qApp pointer.
I have no idea what it means.
4.
 In the testdlg. h file, define qwinwidget * widget; 5.
 Then it's easy.
Add widget = new qwinwidget (this) to the oncreate function of ctestdialog );
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 ();6.
 InCtestdialogOfOndestroyMethod:

Delete widget;

Widget = 0;

7. InQmake-ProjectGenerated. ProFile:

Defines-= Unicode

Defines + = _ afxdll winver = 0x0500

Include (../src/qtwinmigrate. PRI)

Otherwise, it cannot be compiled.

8. Qmake nmakeRun

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.