• 4868阅读
  • 10回复

Qt 5.7编译独立的designer [复制链接]

上一主题 下一主题
离线spygg
 

图酷模式  只看楼主 倒序阅读 楼主  发表于: 2019-03-28
主要工作是将lib文件进行抽离,从而避免对QtDesignerComponents 和 QtDesigner 的DLL依赖,而且可以任性的修改为我所用.

效果:
     学到了如何将系统已有的文件"整块移植"

已知问题:
    release在QtCreator直接编译运行程序会崩溃(可以通过windeployqt引入相应dll文件后再次运行就OK了), debug版本无此问题


代码来源:
    安装目录下src文件下的工程


要点:
0.将原工程中的除designer.pro和其上级pro之外的pro都屏蔽掉,同时将屏蔽后的pro中的pri文件添加到designer.pro中,注意文件顺序(参考原pro文件),在添加时可以通过在工程上右键"添加到工程"将文件加到pro文件中后,修改为include("相对路径"),从而可以解决相对路径问题
1.增加DEFINES += QT_DESIGNER_STATIC,用来避免dll导出警告(和一部分错误)
2.对于出现的mutidefine问题,可以屏蔽相应的cpp文件达到目的(pri文件中)
3.在编译遇到undefine refrence之类的问题时,仔细辨别如果缺失没问题,这时删除所有新生成的文件重新编译也许是个不错的主意
4.在release模式崩溃时,使用windeployqt 将所需dll拷贝过去即可
5.屏蔽掉工程中的Q_INIT_RESOURCE(widgetbox);之类的东西(只有插件才需要初始化资源)
6.如果要修改和系统重名的(DLL中的东西)可通过修改包含文件, 如将#include <QtDesigner/QDesignerComponents> 替换为#include "../lib/components/qdesigner_components.h"
7. 在工程中加上如下代码可以排除对designer模块的依赖
INCLUDEPATH += ../../../../include/QtDesigner/5.7.0../../../../include/QtDesigner/5.7.0/QtDesigner../../../../include/QtDesigner
8.在编译设置的自定义步骤的方式可以添加批处理文件来达到自动化的目的
window.open('http://www.qtcn.org/bbs/attachment/Mon_1903/44_151927_3a089b2de00280f.png?482');" style="max-width:700px;max-height:700px;" onload="if(is_ie6&&this.offsetWidth>700)this.width=700;" >

9.在编译设置中修改编译参数-j8(本次有效)或者在系统环境变量中增加(一劳永逸)来大大的加快编译进程


拷贝.bat文件
  1. echo off
  2. set PATH=C:\Qt\Qt5.7.0\5.7\mingw53_32\bin;C:/Qt/Qt5.7.0/Tools/mingw530_32\bin;%PATH%
  3. IF EXIST ..\build-designer-Desktop_Qt_5_7_0_MinGW_32bit-release\src\designer\bin\designer.exe. IF NOT EXIST ..\build-designer-Desktop_Qt_5_7_0_MinGW_32bit-release\src\designer\bin\Qt5Core.dll. windeployqt ..\build-designer-Desktop_Qt_5_7_0_MinGW_32bit-release\src\designer\bin\designer.exe




designer.pro文件
  1. QT += core-private widgets xml network gui-private
  2. QT += widgets-private
  3. #QT += designer-private designercomponents-private
  4. qtHaveModule(printsupport): QT += printsupport
  5. INCLUDEPATH +=
  6.     ../lib/sdk
  7.     ../lib/components
  8.     ../lib/extension
  9.     ../lib/shared
  10.     ../components
  11.     extra
  12. INCLUDEPATH +=
  13.     ../../../../include/QtDesigner/5.7.0
  14.     ../../../../include/QtDesigner/5.7.0/QtDesigner
  15.     ../../../../include/QtDesigner
  16. RESOURCES += designer.qrc
  17. contains(QT_CONFIG, static) {
  18.     DEFINES += QT_DESIGNER_STATIC
  19. }
  20. DEFINES += QT_DESIGNER_STATIC
  21. include(../lib/extension/extension.pri)
  22. include(../lib/shared/shared.pri)
  23. include(../lib/sdk/sdk.pri)
  24. include(../lib/uilib/uilib.pri)
  25. include(../../../shared/fontpanel/fontpanel.pri)
  26. include(../../../shared/qttoolbardialog/qttoolbardialog.pri)
  27. include(../components/propertyeditor/propertyeditor.pri)
  28. include(../components/objectinspector/objectinspector.pri)
  29. include(../components/signalsloteditor/signalsloteditor.pri)
  30. include(../components/formeditor/formeditor.pri)
  31. include(../components/widgetbox/widgetbox.pri)
  32. #include(../components/buddyeditor/buddyeditor.pri)
  33. include(../components/taskmenu/taskmenu.pri)
  34. #include(../components/tabordereditor/tabordereditor.pri)
  35. SOURCES +=  ../components/lib/qdesigner_components.cpp
  36. HEADERS +=
  37.     qdesigner.h
  38.     qdesigner_toolwindow.h
  39.     qdesigner_formwindow.h
  40.     qdesigner_workbench.h
  41.     qdesigner_settings.h
  42.     qdesigner_actions.h
  43.     qdesigner_appearanceoptions.h
  44.     saveformastemplate.h
  45.     newform.h
  46.     versiondialog.h
  47.     designer_enums.h
  48.     appfontdialog.h
  49.     preferencesdialog.h
  50.     assistantclient.h
  51.     mainwindow.h
  52. SOURCES += main.cpp
  53.     qdesigner.cpp
  54.     qdesigner_toolwindow.cpp
  55.     qdesigner_formwindow.cpp
  56.     qdesigner_workbench.cpp
  57.     qdesigner_settings.cpp
  58.     qdesigner_actions.cpp
  59.     qdesigner_appearanceoptions.cpp
  60.     saveformastemplate.cpp
  61.     newform.cpp
  62.     versiondialog.cpp
  63.     appfontdialog.cpp
  64.     preferencesdialog.cpp
  65.     assistantclient.cpp
  66.     mainwindow.cpp
  67. #PRECOMPILED_HEADER=qdesigner_pch.h
  68. FORMS += saveformastemplate.ui
  69.     preferencesdialog.ui
  70.     qdesigner_appearanceoptions.ui
  71. win32 {
  72.    RC_FILE      = designer.rc
  73. }
  74. DESTDIR         = bin

工程代码
win7可直接编译版本 calcProject_base_ok.zip (6576 K) 下载次数:28


签名就是这么浪
离线liudianwu

只看该作者 1楼 发表于: 2019-03-29
编译出来后的exe双击运行会崩溃,环境没有问题的,其他exe双击都可以正常运行,构建套件一致,不知道什么原因!
欢迎关注微信公众号:Qt实战 (各种开源作品、经验整理、项目实战技巧,专注Qt/C++软件开发,视频监控、物联网、工业控制、嵌入式软件、国产化系统应用软件开发)QQ:517216493  WX:feiyangqingyun  QQ群:751439350
离线spygg

只看该作者 2楼 发表于: 2019-03-31
我是用的mingw32版本的Qt
签名就是这么浪
离线spygg

只看该作者 3楼 发表于: 2019-03-31
在两台电脑上编译都没问题,没试过vs版本的
本帖提到的人: @liudianwu
签名就是这么浪
离线liudianwu

只看该作者 4楼 发表于: 2019-03-31
编译是没有问题,能正常生成exe,但是exe不能用,不知道是不是我这边环境有关系。
欢迎关注微信公众号:Qt实战 (各种开源作品、经验整理、项目实战技巧,专注Qt/C++软件开发,视频监控、物联网、工业控制、嵌入式软件、国产化系统应用软件开发)QQ:517216493  WX:feiyangqingyun  QQ群:751439350
离线spygg

只看该作者 5楼 发表于: 2019-03-31
估计是了,我这边能运行,release版本的要用windeployqt把DLL拷贝过去就行,debug可以直接运行
本帖提到的人: @liudianwu
签名就是这么浪
离线spygg

只看该作者 6楼 发表于: 2019-05-10
回 liudianwu 的帖子
liudianwu:编译是没有问题,能正常生成exe,但是exe不能用,不知道是不是我这边环境有关系。 (2019-03-31 09:57) 

给你一个动态库版本(Qt5的)记得你以前发帖中只有Qt4版本可编译Qt5可编译的Designer/

签名就是这么浪
离线mscheng

只看该作者 7楼 发表于: 2019-05-11
回 spygg 的帖子
spygg:
给你一个动态库版本(Qt5的)记得你以前发帖中只有Qt4版本可编译Qt5可编译的Designer/


编译不成功!一些文件找不到。
离线usercntq

只看该作者 8楼 发表于: 2021-03-04
可以编译通过,非常好!
hello,world,i am back.
离线diskgetor

只看该作者 9楼 发表于: 2021-06-24
tXml -I/usr/include/qt6/QtNetwork -I/usr/include/qt6/QtCore -I/usr/include/qt6/QtUiPlugin -I.moc -I.uic -I/usr/lib/qt6/mkspecs/linux-g++ -o .obj/deviceskin.o ../../../shared/deviceskin/deviceskin.cpp
../../../shared/deviceskin/deviceskin.cpp:53:10: ??????????QtCore/QRegExp????????????????????
   53 | #include <QtCore/QRegExp>
      |          ^~~~~~~~~~~~~~~~
??????????
make[2]: *** [Makefile:3597??.obj/deviceskin.o] ???? 1
make[2]: ??????????/home/ddk/Desktop/calcProject_base_ok/src/designer/src/designer??
make[1]: *** [Makefile:47??sub-designer-make_first] ???? 2
make[1]: ??????????/home/ddk/Desktop/calcProject_base_ok/src/designer/src??
离线lixinwei

只看该作者 10楼 发表于: 2021-06-25
回 diskgetor 的帖子
diskgetor:tXml -I/usr/include/qt6/QtNetwork -I/usr/include/qt6/QtCore -I/usr/include/qt6/QtUiPlugin -I.moc -I.uic -I/usr/lib/qt6/mkspecs/linux-g++ -o .obj/deviceskin.o ../../../shared/deviceskin/deviceskin.cpp
../../../shared/deviceskin/deviceskin.cpp:53:10: ??????????Q .. (2021-06-24 11:32)

改成 #include <QtCore5Compat/QRegExp>
在pro文件的相应位置添加:QT += core5compat

在Qt6中,QRegExp和其他一些不推荐使用的类已经从QtCore模块移动到了QtCore5Compat模块,以方便日后彻底删除它们,请参考文档 https://doc.qt.io/qt-6/qtcore5compat-module.html




快速回复
限100 字节
 
上一个 下一个