Windows下Qt 插件开发

Windows下Qt 插件开发

   注:本文只针对Windows环境 

    关于Qt 插件的编译在Qt Assistant中有详细的说明,而且有具体的例子,这里不再赘述。笔者主要谈谈如何在Widget Box中显示自定义的

控件。

    一,在QtDesigner中显示自定义控件

    这一步比较简单,如果Designer是用MingW版本的,则用MingW编译好插件,拷贝到E:\Qt\4.8.0\plugins\designer(以笔者目录为例),

如果是用MSVC编译的,则也用MSVC编译好插件,拷贝到以上目录。这里需要注意的是由于Designer是Release版本,所以插件也需要编译

成Release版本。

  二,在QtCreator中显示自定义控件

   由于官方下载的Creator(最新版本是Qt2.4.1)是用MSVC编译的,如果你用的是MingW编译的插件则需要从官网下载Creator源码也用

MingW来编译。关于编译中可能有的错误可以参考:http://www.devbean.info/2011/08/qtcreator-plugin-develop-1/,也可以参考源码中的

README文件。

   而笔者编译Qt2.4.1的时候还发现一个错误,具体是哪个文件忘了,反正就是头文件中有三个函数不能声明成inline函数,打开此文件,去掉

这三个函数中的inline关键字即可。需要注意的是插件和Creator编译成Debug还是release版本要一致。编译成功后打开Creator就可以看到自

定义的控件里。(笔者判断Creator中显示的自定义插件是从plugins\designer目录中的动态库读取的)


三,在Qt集成的Eclipse中显示自定义控件

 关于这个问题Nokia官网上是这样描述的:

If you want to create your own designer plugins you will need to create them with the same version that the integration was built with (currently Qt 4.6). Qt must be configured with '-qtnamespace QtCppIntegration' on Windows, and with '-qtnamespace QtCppIntegration -qtlibinfix CppIntegration' on Linux as of Qt Eclipse Integration 1.4.3, to create custom designer plugins.

参考 http://qt.nokia.com/products/eclipse-integration/

Custom Designer Plugins

It is possible to add widgets from a custom designer plugin to the Widget Box of the Qt Eclipse Integration, just as it is for the standalone

 Qt Designer application. To do so, you need to perform the following steps:

  1. Build your custom designer plugin with the same Qt version as Qt Designer Plugin, configured with-qtnamespace
  2.  QtCppIntegrationin release mode, e.g. for Qt Designer Plugin 1.4.3, you need Qt 4.4.3. The Qt configure command will look like
  3.  this:./configure -release -qtnamespace QtCppIntegration -qtlibinfix CppIntegration
  4. Put your Qt Designer plugin libraries in thecom.trolltech.qtcppcppdesignerpluginsdirectory in Eclipse's plugins directory.
  5.  Depending on the location of your Eclipse installation, the directory may be in one of the following locations:
  6. Linux: /usr/local/eclipse/plugins/com.trolltech.qtcppcppdesignerplugins /usr/lib/eclipse/plugins/com.trolltech.qtcppcppdesignerplugins Windows: C:\\eclipse\\plugins\\com.trolltech.qtcppcppdesignerplugins
  7. Make sure that your plugin finds all its dependencies.

参考:http://doc.qt.nokia.com/qt-eclipse-1.6/eclipse-integration-custom-designer-plugins.html

 

     笔者按照这样的要求,下载Qt4.6.1(因为Eclipse Integration是用Qt4.6.1编译的)来编译插件(笔者运行configur命令的时候还有一个错

误,就是qlocale.cpp中找不到float.h。改为#include 即可),拷贝到相应目录,但还是不行。网上说

可能是MingW的版本不行,但我下载了好几个版本,还是不成功。

    希望已经解决此问题的大牛能指点指点小菜。

你可能感兴趣的:(QT)