LInk Qt framework to an MFC project



  • Hello, I have compiled the source of the Qt framework using the visual studio compiler, linked everything in the settings dll, libs and headers, and after I tried to create a simple message box in the MFC project but had no luck, the compiler shows this error: error LNK2019 unresolved external symbol... (link error). Not sure why it show me this error because the dll and libs are set in the project properties. Can you help me out? Thanks in advance


  • Qt Champions 2016

    Hi
    it would be helpful if you show the actual linker errors.

    And why an MFC project?
    That normally do not link to the needed Qt dlls.

    Also why did you compiled your own Qt?
    Is is static or what is special about it?



  • @mrjj
    Error 2 error LNK2019: unresolved external symbol "_declspec(dllimport) public: virtual __thiscall QMessageBox::~QMessageBox(void)" (__imp??1QMessageBox@@UAE@XZ) referenced in function "public: virtual void * __thiscall QMessageBox::`scalar deleting destructor'(unsigned int)" (??_GQMessageBox@@UAEPAXI@Z)

    It's just for learning. I have an MFC old project (used it for learning MFC) and now I just want to use the Qt ui in MFC project, to learn something new. No, the application is not static. So compiling was not a good idea(
    in the InitInstance fucntion (MFC) I'm just trying to create a QMessageBox: QMessageBox *p = new QMessageBox


  • Qt Champions 2016

    Hi
    Ok seems you are not linking to the Qt dlls.
    Also how will you handle the event loop?
    Do you create a QApplication object also?

    Mixed MFC and Qt might be really hard.



  • @mrjj No I'm not creating a QApplication object. Do I have to create it in order to make a test QMesssageBox?
    I red that creating a secondary thread solves the issue, and also I checked that I will have to re-write the MFC signals so that Qt UI would be able to catch them. But in fact I do link to them, In visual studio I set the Reference path to the Qt\bin folder, also I have installed Qt visual studio plugin


  • Qt Champions 2016

    Hi
    Yep you need QApp
    alt text

    The visual studio plugin is not ment for MFC projects. not sure it
    work with that. never tried.

    The error says its not linked. So check compiler output etc and see if you can spot something.



  • @mrjj that's a run-time error. And I have a compile time, I mean that even If i'll create a Qapplication object nothing changes. Why it does not see the dll? Have you tried to connect Qt to MFC? Thanks in advance.


  • Qt Champions 2016

    That is what happens if i make a msg box before the application.
    You will get the same if it linked and ran.

    Sadly i never tried to mix MFC and Qt as what would be the point?
    Both are for GUI so one is enough.

    But i understand you do it for learning. I dont have visual studio IDE so cannot tell you
    if you have added it to the right place.
    http://www.technical-recipes.com/2012/how-to-link-dlls-to-c-projects/

    You could post some images of the dialogs involved and hope that someone can spot
    what is wrong.



  • @mrjj at first I'll try to link Qt libs to a console application, and after will continue with MFC



  • @mrjj did you link Qt to a Visual Studio console project? If yes how did you do that, because I'm having problems with it. Thank you
    UPD: got it working.
    But receiving this error:
    This application failed to start because it could not find or load the Qt platform plugin "windows"
    in "".


  • Qt Champions 2016

    @mandruk1331

    Yes the link shows how the author links a dlls to his project.
    But its 2010 VS so dialog might have changed.


  • Qt Champions 2016

    @mandruk1331 said in LInk Qt framework to an MFC project:

    This application failed to start because it could not find or load the Qt platform plugin "windows"

    That is because it cant find the dlls.
    very normal case when people click the .exe outside of creator.



  • @mrjj I have connected Qt to MFC. Thank you! It now compiles and works


Log in to reply
 

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