Error LNK 2019 when merging QT application with an existing MFC application

  • Hi, I've recently developed a QT application(NewSPOISGUI) which was to serve as a new front end to a legacy MFC application at work. This application compiles and runs perfectly when standalone. I'm using QT 4.8.2 with VS2008 SP1 and the add-in.

    Currently, I'm trying to test the functionality and trying to make the Qt GUI appear instead the of the old MFC application GUI. As a test I included the header file(newspoisgui.h) from the Qt application in the MFC application within VS2008. Unfortunately, despite adding the same paths and libraries as the Qt application(NewSPOISGUI), I keep encountering :

    qtmaind.lib(qtmain_win.obj) : error LNK2019: unresolved external symbol _main referenced in function _WinMain@16
    Debug/SPOIS.exe : fatal error LNK1120: 1 unresolved externals

    None of the solutions I could find online could be applied as they weren't for using Qt in VS2008. Any help would be greatly appreciated. Thanks in advance.

  • You should only use the qtmain lib if you do not have already defined a WinMain function. This library simply wrapps the standard C @int main(int argc, char** argv)@ in a WinMain call because that's what Windows expects. This library sole purpose is to have a cross platform entry point in the application.
    If your MFC application already has the WinMain function, you should just instantiate your QApplication in that method and call @exec()@ on that instance from there and remove the linking to the qtmain library.

  • Okay, I'll try that. What if the application doesn't have a WinMain() function? Would just calling the exec() function from the MFC initialization function trigger the Qt Application?

    Thanks again for the assist.

    p.s : what would be the best way of integrating the MFC solution with the Qt application solution? Or is it better to manually import the header files and add the contents of the .cpp file to the main.cpp of the MFC solution?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.