November 24, 2011

ReaMix ReaMix
Lab Rat
3 posts

Change Standalone Qt App into Plugin for VS Project

 

Using Visual Studio 2008 with the Qt VS add-in, I built a standalone Qt application. Now I want to change its build so another VS project can use it as a plug-in.

  1. //ExportMe.h
  2. #define EXPORT_THIS Q_DECL_EXPORT
  3. class ExportMeClass : public QWidget {
  4.      Q_OBJECT
  5.      public:
  6.           EXPORT_THIS MyConstructor(QWidget *parent = 0, Qt::WFlags flags = 0);
  7.           ~MyConstructor();
  8. };
  9.  
  10. //ExportMe.cpp
  11. #include "ExportMe.h"
  12. extern "C" {
  13.      ExportMe::MyConstructor(QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags) {
  14.           ui.setupUi(this);
  15.      }
  16.      ExportMe::~MyConstructor() {}
  17. }
  18.  
  19. //main.cpp
  20. #include "ExportMe.h"
  21. #include <QtGui/QApplication>
  22. int main(int argc, char *argv[]) {
  23.      QApplication a(argc, argv);
  24.      ExportMe e;
  25.      e.show();
  26.      return a.exec();
  27. }

—————————————————————-
New Project
—————————————————————-
  1. //IntegratedProj.cpp
  2. #include "ExportMe.h"
  3. IntegratedProj::MyConstructor(QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags) {
  4.      ExportMe::MyConstructor(parent, flags);
  5. }

—————————————————————-
The Problem
—————————————————————-
The combined project does not run the plug-in. I have tried the following:

1) Left the Project Properties the same for both projects, only adding Linker dependencies to IntegratedProj. This produced ExportMe.lib and ExportMe.exe. When I run depends.exe on IntegratedProj.exe, it requires the ExportMe.exe to be in the same directory. This allowed the IntegratedProj to recognize the plug-in, but it did not display the form file (UI). Prefer if final solution does not require adding the ExportMe executable to the IntegratedProj directory (prefer to share a dll).
2) Changed the Project Properties for ExportMe project so it’s General Configuration Type was set to .dll and the Linker Output File was set to .dll. This fails to compile due to Linker error (it cannot find the ExportMe.lib file). This Build configuration does not create a lib file though.

How can I modify my solution, either in code or Build Properties, to turn the standalone Qt application into a plug-in for a Visual Studio project?

1 reply

November 24, 2011

koahnig koahnig
Mad Scientist
2185 posts

How about creating a separate project for your dll/lib?
An additional project for your ExportMe.exe. The second project will certainly have to access the dll/lib.

Depending on the size of the dll/lib part this may be the fastest way to get to a solution.

 
  ‹‹ websockets client api in Qt (C++)      [Solved][Qt concurrent] Emit signal from run method do not work ››

You must log in to post a reply. Not a member yet? Register here!