添加Qt Widgets 设计器插件
通过创建扩展 Qt 应用程序的插件,将控件添加到Qt Widgets Designer 中。
您可以创建插件,将自定义控件添加到Qt Widgets Designer中。若要将插件包含到应用程序中,请将其编译为动态库并单独分发,应用程序将在运行时检测并加载该库。
应用程序可在标准的插件子目录中检测到插件。有关如何创建和定位插件以及如何更改默认插件路径的更多信息,请参阅《如何创建 Qt 插件》。
有关如何为Qt Widgets Designer创建插件的更多信息,请参阅《在Qt Widgets Designer中使用自定义控件》。
查找Qt Widgets 设计器插件
Qt Widgets Designer会从标准位置检索插件,并加载与其构建键匹配的插件。Qt Widgets Designer既可作为独立应用程序使用,也可集成到Qt Creator 中。放置插件的正确文件夹取决于您使用的是独立版的Qt Widgets Designer,还是集成版的Qt Widgets Designer。
集成版Qt Widgets Designer 从Qt Creator 的安装目录中获取插件。在 Windows 系统上,Designer 插件从<QtCreator>\bin\plugins\designer 加载;在 Linux 系统上,从<QtCreator>/lib/Qt/plugins/designer 加载;而在 Qt Creator.app/Contents/PlugIns/designer macOS系统中加载。
要查看哪些插件已成功加载、哪些加载失败,请选择“Tools ” > “Form Editor ” > About Qt Widgets Designer Plugins。
独立版的Qt Widgets Designer是Qt库的一部分,用于构建项目,位于Qt安装目录下的<Qt_version>\<compiler>\bin 中。它从bin 的\plugins\designer 子目录中加载插件。要检查哪些插件已成功加载、哪些加载失败,请在Linux和Windows系统上选择Help >About Plugins (或在 Qt Creator 在 macOS 上选择 >About Plugins )。
匹配构建密钥
Windows 系统上预编译 Qt 软件包中包含的Qt Creator 是使用 Microsoft Visual Studio 编译器构建的。如果您安装的 Qt 版本是使用 MinGW/g++ 编译器构建的,则Qt Creator 将无法加载使用 Windows 版本构建的插件,因为构建密钥不匹配。
如果您使用的 Qt 版本比Qt Creator 构建时所用的 Qt 版本更新,或者存在其他不兼容情况,也会出现同样的问题。此时,这些插件只能在Qt Widgets Designer 的独立版本中使用。请选择“Help ”> About Qt Creator 以检查Qt Creator 的构建所使用的 Qt XML 版本和编译器。
若要使用针对随附 Qt 版本构建的Qt Widgets Qt Designer 插件,请确保Qt Creator 也是使用相同的编译器构建的。具体操作取决于您希望为应用程序采用的配置:要么使用 MinGW 重新编译Qt Creator ,要么安装使用 Microsoft Visual Studio 构建的 Qt 版本。
另请参阅 教程:《Qt Widgets 应用程序》和《Qt Widgets 设计器》。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.