QT4与QT5兼容问题

QT4 与QT5 兼容,源码差异部分通过QT_VERSION 宏来区分

常见区别

  1. widgets prinsupport charts 等模块一如方式,Qt5 将QtWidgets QtPrintsupport 模块从QtGui 中分离出来,QT4 中没有qjson4 和 charts 模块,需要特殊处理
    在pro文件中,按需添加如下内容。
QT += core gui

greaterThan(QT_MAJOR_VERSION,4{
#根据需要引入QT5的widgets printsupport charts 模块

QT +=  widgets  widgets  widgets 
QT += uitools
win32: QT += axcontainer
}
else{
#根据需要在QT4引入qjson4 和 charts模块
INCLUDEPATH += $$(SMART_HOME)/dev/include/qjson4/ $$(QTDIR)/include/
$$(QTDIR)/include/QtCharts/
LIBS += -lqjson4 -lQtCharts
CONFIG += uitools
win32: CONFIG += qaxcontainer
}
DEPENDPATH += $$INCLUDEPATH

QT += core widgets 改 QT += core gui
QT += uitools 改为 CONFIG += uitools
QT += axcontainer 改为 CONFIG += qaxcontainer

如果链接时出现一下错误
在这里插入图片描述
在.pro文件中还需添加

win32{
	LIBS += -lFT_ET99_API -lET_OTPVerify -lZAZAPIt
}
else{
	LIBS += -lFT_ET99 -letotpverify -lzazlibPC64
}

在源代码中根据QT_VERSION 宏区分QT版本
#if QT_VERSION > 0x050000 //qt5.0以上的版本
#include
#endif
#include …

插件接口定义区别

class DONUT_CHART_PLUGIN_LIB_EXPORY CDonutChartPlugin : public QObject , public PluginWidgetFactoryInterface
{
	Q_OBJECT
	#if QT_VERSION  > 0x050000
	Q_PLUGIN_METADATA(IID PluginWidgetFactoryInterface_iid)
	Q_INTERFACES(PluginWidgetFactoryInterface)
}

在cpp文件末尾添加如下内容

#if QT_VERSION  《 0x050000
Q_PLUGIN_EXPORT2(donutchartwidget,CDonutChartPlugin)
#endif

其中CDonutChartPlugin为接口实现类的名称,donutchartwidget 与pro文件中的target变量一致,即插件so包的名称

枚举类型常量写法,去掉枚举类型名

Qt::Orientation::Vertical 改为 Qt::Vertical
Qt::Variant::Tpye::Int   改为 Qt::Variant::Int

容器套容器 右边尖括号增加空格

QMap<long,QVecor<double> >  tmp; 

其他问题

QComBox 的currentData()函数,QT4中无此函数
int cur = ui.combox->currentData().toInt();
改为
int cur = ui.combox->itemData( ui.combox->currentIndex().toInt());

没有setCurrentText()函数
改为setCurrentIndex(combx->findText(txt));

QCompleter 没有setFilterMode 函数
改为

#if QT_VERSION  > 0x050000
 pCompleter.setFilterMode();
#endif

QHeader 区别处理
setClickable ⇒ setSectionsClickable(true)

void mouseDoubleClickEvent() Q_DECL_OVERRIDE
去掉Q_DECL_OVERRIDE

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值