Important: Please read the Qt Code of Conduct -

Questions and doubts about porting MFC GUI to Qt

  • Hi Qt community,
    I've a large MFC project that I would like to migrate to Qt. The structure of MFC projects is the following:
    I've a dynamic MFC library that calls methods of a secondary MFC STATIC library . The goal is to migrate to Qt both libraries and remove MFC. I'm following the instructions suggested in but I've some problems:

    1. MFC DINAMIC library doesn't call Run method (this is correct because it is a dll), for this reason I've created QtApplication in CWinApp::InitInstance and destroyed in CWinApp::ExitInstance but I'm not able to understand where is the correct place to put qApp->exec(). Please, could you tell me where I can set this call?
      I tried to put qApp->exec() in CWinApp::InitInstance but it isn't the correct place because I have a runtime error and in general when I call it in another point of my code the result is that the application doesn't work anymore.
      Do you think it is a good idea to overwrite CWinApp::PreTranslateMessage in this way?
      virtual BOOL CMyWinApp::PreTranslateMessage(MSG* pMsg)
      if (qApp)
      return CWinApp::PreTranslateMessage(pMsg);
    2. I converted an old MFC dialog in QDialog and it seems quite easy but when the QDialog appears I've two black areas and the Slots associated to the ui objects are not executed. Is it probably due to a missing qApp->exec() that provides to start messages pump?
    3. As mentioned at the begin the MFC DINAMIC dll calls a MFC STATIC library and both should be moved to Qt. It this a problem? Can I mix dynamic and static qt libraries or this mix could generate a problem for the deployment?
      Thanks in advance for your help. Please ask me details and sorry for my rough english :)

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Which part are you following ?

    IIRC, there's an example showing how to progressively move from full MFC to Qt.

    As for you questions, number 3, I can answer, no issue with that.

  • @SGaist said in Questions and doubts about porting MFC GUI to Qt:

    As for you questions, number 3, I can answer, no issue with that.

    Thanks a lot for your answer.
    About the question number 1 and 2 I found a solution that correctly works . I've studied the example contained in (unfortunately it's not possible to execute/debug them due to build error but I made some code inspection and analyzed every line of QMfcApp class provided by Qt to perform a good migration).
    Solution question1:
    BOOL MyWinApp::InitInstance()
    BOOL result = CWinApp::InitInstance();
    if (result)
    return result;
    int MyWinApp::ExitInstance()
    if (qApp)
    delete qApp;
    return CWinApp::ExitInstance();
    The PretranslateMessage is not needed because the QMfcApp::instance(this); provide to hook the Qt messages.
    Solution question 2:
    The black areas are due to call CWinHost* pHost = new CWinHost(..);
    The connect problem has been solved using the new syntax like this:
    connect(ui.myButton, &QPushButton::clicked, this, &CMyDialog::OnMyButtonSlot);

    I hope this could be useful for all developers :)

    Thanks again.

  • Lifetime Qt Champion

    Glad you solved it and thanks for sharing !

    Happy coding

Log in to reply