Hi there, I got some problem when using QPluginLoader.
1) Firstly, I wrote the interface named “tcpPlunginInterface.h”. The content:

Qt Code:
  1. #ifndef TCPPLUGININTERFACE_H
  2. #define TCPPLUGININTERFACE_H
  3.  
  4. #include "tcpclient_os.h"
  5.  
  6. class tcpPluginInterface
  7. {
  8. public:
  9.  
  10. virtual tcpClient_Os* getPluginInst( VhostInfo hostInfo, CtcpOpt *tcpOpt,
  11. QObject *parent = 0) = 0;
  12. };
  13.  
  14. QT_BEGIN_NAMESPACE
  15. Q_DECLARE_INTERFACE(tcpPluginInterface,"ltcpOSDLL/1.0.0")
  16. QT_END_NAMESPACE
  17.  
  18. #endif // TCPPLUGININTERFACE_H
To copy to clipboard, switch view to plain text mode 
2) Secondly, I wrote a class called “ltcpOS”. The instance of this class contained a function “getPluginInst”, which would return a point type.
“ltcpOS.h”:
Qt Code:
  1. #ifndef LTCPOS_H
  2. #define LTCPOS_H
  3.  
  4. #include <QObject>
  5. #include <QtPlugin>
  6. #include "tcpPluginInterface.h"
  7.  
  8. class ltcpOS : public QObject,tcpPluginInterface
  9. {
  10. Q_OBJECT
  11. Q_INTERFACES(tcpPluginInterface)
  12. public:
  13. ltcpOS();
  14. ~ltcpOS();
  15.  
  16. tcpClient_Os* getPluginInst( VhostInfo hostInfo, CtcpOpt *tcpOpt,
  17. QObject *parent = 0);
  18. //the “tcpClient_Os” is a self-defined class.
  19.  
  20. public:
  21. tcpClient_Os *os;
  22.  
  23. signals:
  24.  
  25. public slots:
  26.  
  27. };
  28.  
  29. #endif // LTCPOS_H
To copy to clipboard, switch view to plain text mode 
“ltcpos.cpp”:
Qt Code:
  1. #include "ltcpos.h"
  2.  
  3. ltcpOS::ltcpOS()
  4. {
  5. }
  6.  
  7. ltcpOS::~ltcpOS()
  8. {
  9. os->deleteLater();
  10. }
  11.  
  12. Q_EXPORT_PLUGIN2(ltcpOS,ltcpOS)
  13.  
  14. tcpClient_Os *ltcpOS::getPluginInst(VhostInfo hostInfo, CtcpOpt *tcpOpt, QObject *parent)
  15. {
  16. os = new tcpClient_Os(hostInfo, tcpOpt);
  17. return os;
  18. }
To copy to clipboard, switch view to plain text mode 
Then I compiled these file in release mode, and generated a “ltcpOS1.dll” DLL file. So I could load it and use it in other project.

The problem I encountered is, when I use a QPluginLoader to load the DLL, QT doesn’t know what the return value is. This is my code which loads the DLL:
Qt Code:
  1. QPluginLoader dllLoader("E:/QTProject/tcpClient3/ltcpOS1.dll");
  2.  
  3. QObject *tcpObj = dllLoader.instance();
  4.  
  5. if(!tcpObj)
  6. {
  7. qDebug() << dllLoader.errorString();
  8. return;
  9. }
  10.  
  11. tcpPluginInterface *os_inst = qobject_cast<tcpPluginInterface*>(tcpObj);
  12.  
  13. client = os_inst->getPluginInst(hostInfo, &ProtIOBuf);
  14.  
  15. client->run();
To copy to clipboard, switch view to plain text mode 

I have included the header file such like “tcpClient_os.h”, and add “QT += network” to the *.pro file, but I still get the compile errors:
error:undefined reference to `tcpClient_Os::run()'
error:undefined reference to `tcpClient_Os::slot_stop()'
…..etc



But When I add the all the cpp files (such like tcpClient_os.cpp), which contains the all implement part, to the *.pro. It’s OK. I don’t want to add those cpp files because that made my DLL useless. I’m going to be insane about that problem, it bother me more than a week…Please,help.