Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Constructor Initialization Fails



  • Hi, I am new to Qt/QtCreator world - I have been traditionally on Visual Studio. But seeing the kind of dynamism in the world, I was so excited learning what is what. Finally, I thought of doing a simple porting stuff from VS to Qt way. I failed and spent many days without any productivity. But what I am doing is damn simple.

    Here is what I used to do in VS2017 -

    class MyApiClient 
    {
    private:
        CManagerFactory   m_factory;
        CManagerInterface *m_manager;
    public:
    	MyApiClient() : m_factory("mymanapi64.dll"), m_manager(NULL)
    	{
    	   // constructor code
    	}
    

    When I tried it on Qt it did not work... and try many different ways like -

    I tried this
    I played around with QLibrary. Though my DLL gets loaded successfully using QLibrary Library(xxxx.dll).

        QLibrary library("C:/xx/MyWorkspace/Qt/mymanapi64.dll");
        if (!library.load()) {
          qDebug() << library.errorString();
        }
        else {
          qDebug() << "It loaded successfully";     // <- I get this message!!
    	 }
    

    BUT.... i do not know how to get the class member (m_factory) initialized using QLibrary in the similar way that I could do it in VS .

    Note This is a 3rd party .dll and along with that i have only a header and no libraries. I need to get the CManagerFactory instance, and start working on that. But I am stuck at this... you would not believe me, I wasted 20+ hours only this :(

    For Qt experts, maybe this could be a cake-walk. I would really appreciate if someone could throw lights on this.

    Thanks,
    Tharma


  • Lifetime Qt Champion

    @Tharma

    you need to use resolve and cast the result to your functions signature.

    That is pure C/C++ basic and nothing special to Qt. QLibrary uses Windows API LoadLibrary behind the scenes (and similar calls on other OS) but provides you a convenient API.

    Regards


Log in to reply