查看完整版本: [-- Qt 5.7编译独立的designer --]

QTCN开发网 -> Qt 作品展 -> Qt 5.7编译独立的designer [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

spygg 2019-03-28 21:00

Qt 5.7编译独立的designer

主要工作是将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.在编译设置的自定义步骤的方式可以添加批处理文件来达到自动化的目的
[attachment=20057]

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


拷贝.bat文件
  1. echo off
    set PATH=C:\Qt\Qt5.7.0\5.7\mingw53_32\bin;C:/Qt/Qt5.7.0/Tools/mingw530_32\bin;%PATH%
    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
    QT += widgets-private
    #QT += designer-private designercomponents-private
    qtHaveModule(printsupport): QT += printsupport

    INCLUDEPATH +=
        ../lib/sdk
        ../lib/components
        ../lib/extension
        ../lib/shared
        ../components
        extra

    INCLUDEPATH +=
        ../../../../include/QtDesigner/5.7.0
        ../../../../include/QtDesigner/5.7.0/QtDesigner
        ../../../../include/QtDesigner

    RESOURCES += designer.qrc

    contains(QT_CONFIG, static) {
        DEFINES += QT_DESIGNER_STATIC
    }

    DEFINES += QT_DESIGNER_STATIC

    include(../lib/extension/extension.pri)
    include(../lib/shared/shared.pri)
    include(../lib/sdk/sdk.pri)


    include(../lib/uilib/uilib.pri)


    include(../../../shared/fontpanel/fontpanel.pri)
    include(../../../shared/qttoolbardialog/qttoolbardialog.pri)
    include(../components/propertyeditor/propertyeditor.pri)
    include(../components/objectinspector/objectinspector.pri)
    include(../components/signalsloteditor/signalsloteditor.pri)
    include(../components/formeditor/formeditor.pri)
    include(../components/widgetbox/widgetbox.pri)
    #include(../components/buddyeditor/buddyeditor.pri)
    include(../components/taskmenu/taskmenu.pri)
    #include(../components/tabordereditor/tabordereditor.pri)


    SOURCES +=  ../components/lib/qdesigner_components.cpp

    HEADERS +=
        qdesigner.h
        qdesigner_toolwindow.h
        qdesigner_formwindow.h
        qdesigner_workbench.h
        qdesigner_settings.h
        qdesigner_actions.h
        qdesigner_appearanceoptions.h
        saveformastemplate.h
        newform.h
        versiondialog.h
        designer_enums.h
        appfontdialog.h
        preferencesdialog.h
        assistantclient.h
        mainwindow.h

    SOURCES += main.cpp
        qdesigner.cpp
        qdesigner_toolwindow.cpp
        qdesigner_formwindow.cpp
        qdesigner_workbench.cpp
        qdesigner_settings.cpp
        qdesigner_actions.cpp
        qdesigner_appearanceoptions.cpp
        saveformastemplate.cpp
        newform.cpp
        versiondialog.cpp
        appfontdialog.cpp
        preferencesdialog.cpp
        assistantclient.cpp
        mainwindow.cpp

    #PRECOMPILED_HEADER=qdesigner_pch.h

    FORMS += saveformastemplate.ui
        preferencesdialog.ui
        qdesigner_appearanceoptions.ui

    win32 {
       RC_FILE      = designer.rc
    }

    DESTDIR         = bin

工程代码
[attachment=20055]



liudianwu 2019-03-29 21:32
编译出来后的exe双击运行会崩溃,环境没有问题的,其他exe双击都可以正常运行,构建套件一致,不知道什么原因!

spygg 2019-03-31 00:27
我是用的mingw32版本的Qt

spygg 2019-03-31 00:28
在两台电脑上编译都没问题,没试过vs版本的

liudianwu 2019-03-31 09:57
编译是没有问题,能正常生成exe,但是exe不能用,不知道是不是我这边环境有关系。

spygg 2019-03-31 19:22
估计是了,我这边能运行,release版本的要用windeployqt把DLL拷贝过去就行,debug可以直接运行

spygg 2019-05-10 21:26
liudianwu:编译是没有问题,能正常生成exe,但是exe不能用,不知道是不是我这边环境有关系。 (2019-03-31 09:57) 

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


mscheng 2019-05-11 16:17
spygg:
给你一个动态库版本(Qt5的)记得你以前发帖中只有Qt4版本可编译Qt5可编译的Designer/


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

usercntq 2021-03-04 23:14
可以编译通过,非常好!

diskgetor 2021-06-24 11:32
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 2021-06-25 00:09
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






查看完整版本: [-- Qt 5.7编译独立的designer --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled