Qt4升级至Qt5——程序修改&部分错误解决办法

平台:RK3128

版本:Qt4.8.4->Qt5.14.2

一、修改工程Pro文件

Qt5 相较于Qt4的一个比较大的改变是将 widget 从 QtGui 模块中脱离,改为了 QtWidgets 模块。

#.pro文件中增加:
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

二、修改头文件

在Qt5中直接编译Qt4程序会有一大堆头文件找不到,他们大多只是被移动了位置

//Qt4
#include <QWidget>  

修改为:

//Qt5
#include <QtWidgets/QWidget> 

#include <QApplication>  修改为: #include <QtWidgets/QApplication>

#include <QtGui/QTableView>  修改为  #include <QtWidgets/QTableView>

......

三、程序中部分编译错误的解决方法

error: ‘class QHeaderView’ has no member named ‘setResizeMode’

将 setResizeMode 替换为为 setSectionResizeMode


error: ‘class QHeaderView’ has no member named ‘setClickable’; did you mean ‘sectionsClickable’?

替换为为setSectionsClickable


error: use of deleted function ‘QVariant::QVariant(Qt::GlobalColor)’

return QVariant(Qt::black);

修改为

QVariant color_var; 

color_var = QColor(Qt::black);

return color_var;


error: ‘class QString’ has no member named ‘toAscii’ QByteArray ba = str_id.toAscii(); ^~~~~~~

替换为为toLatin1


qcustomplot.o:在函数‘QCustomPlot::savePdf(QString const&, int, int, QCP::ExportPen, QString const&, QString const&)’中:

对‘QPrinter::QPrinter(QPrinter::PrinterMode)’未定义的引用

对‘QPrinter::setOutputFileName(QString const&)’未定义的引用

pro文件中加入qtHaveModule(printsupport): QT += printsupport

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值