MFC与QT混合编程---在MFC程序中使用QT的组件

版权声明

请尊重原创作品。转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正。

 

 

MFC QT 混合编程 --- MFC 程序中使用 QT 的组件

1.        创建一个最简单的 MFC Dialog 程序。

2.        BOOL CTestApp::InitInstance() 函数中增加        
QMfcApp::instance(this);

       跟踪到QMfcApp
的代码中可以清楚的看到该静态函数的功能是创建QApplication
实例。

   3.        
   重写CTestApprun方法。
       如下:
int CTestApp::Run() 
{   
    int result = QMfcApp::run(this);
    delete qApp;
    return result;
}

        这个我也没大搞明白是什么意思。
QT帮助上说:
QMfcApp:run()
 will then use that QMfcApp::instance, which must then be deleted explicitly using the global qApp pointer.
我也没搞懂什么意思。
4.         
   testDlg.h文件中定义:
      QWinWidget *widget;
5.        
   然后就很简单了。
CTestDialogOnCreate函数中加入:
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();  
6.        
    CTestDialog  OnDestroy 方法中: 

       delete widget;

widget = 0;  

7.        qmake –project 生成的 .pro 文件中加入:

DEFINES -= UNICODE

DEFINES += _AFXDLL WINVER=0x0500

include(../../../src/qtwinmigrate.pri)

否则编译不过。

8.        qmake nmake 运行一下

 

你可能感兴趣的:(windows编程,QT,VC)