当前位置: 首页 > news >正文

记录QT5迁移到QT6.8上的一些问题

经常看到有的同学说网上的教程都是假的,巴拉巴拉,看看人家发布时间,Qt官方的API都会有所变动,多搜索,多总结,再修改记录。
 

下次遇到问题多这样搜索  QT 4/5/6   xxx  document,对比一下就知道变动了

1.'endl' was not declared in this scope

qDebug()<<data.toHex()<<endl;


endl改成Qt::endl

qDebug()<<data.toHex()<<Qt::endl;

2.Qt6移除了<QDesktopWidget>的问题


..\..\mainwidget.h:6:10: fatal error: QDesktopWidget: No such file or directory

修改前:

//头文件
#include <QDesktopWidget>//CPP文件QDesktopWidget* desktopWidget = QApplication::desktop();QRect screenRect = desktopWidget->screenGeometry();currentScreenWid = (screenRect.width());currentScreenHei = (screenRect.height() - 100);this->setFixedSize(currentScreenWid,currentScreenHei);

改成:

//头文件
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QScreen>
#else
#include <QDesktopWidget>
#endif//CPP文件
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)QScreen *pScreen = QApplication::primaryScreen();currentScreenWid = (pScreen->geometry().width());currentScreenHei = (pScreen->geometry().height() - 100);
#elseQDesktopWidget* desktopWidget = QApplication::desktop();QRect screenRect = desktopWidget->screenGeometry();
//    currentScreenWid = (screenRect.width()*3/4);
//    currentScreenHei = (screenRect.height()*4/5 - 100);currentScreenWid = (screenRect.width());currentScreenHei = (screenRect.height() - 100);
#endifthis->setFixedSize(currentScreenWid,currentScreenHei);

3.error: 'class QGridLayout' has no member named 'setMargin'

使用setContentsMargins替代

    gridlayout_left->setContentsMargins(0,25,0,20);gridlayout_right->setContentsMargins(0,25,0,20);

4.调用的库是32位的

QT6下载的编译器都是64位的,把32位库文件换成64位。

OK,运行了

5.部分信号与槽没反应,估计是Qt4格式的,过时了

qt.core.qobject.connect: QObject::connect: No such signal QButtonGroup::buttonClicked(int) in ..\..\menubarwid.cpp:82

connect(pushButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slot_btnGroupClicked(int)));

好家伙居然还是用的Qt4的信号

Qt5就已经过时了,但是调用依然有效

Qt6彻底删了

修改位idClicked(int)后正常:

connect(pushButtonGroup, SIGNAL(idClicked(int)), this, SLOT(slot_btnGroupClicked(int)));

后面有啥问题再记录吧

http://www.lryc.cn/news/496401.html

相关文章:

  • 清理Linux/CentOS7根目录的思路
  • 【LInux】kvm添加u盘启动引导
  • .net XSSFWorkbook 读取/写入 指定单元格的内容
  • GaussDB(类似PostgreSQL)常用命令和注意事项
  • 【HM-React】02. React基础-下
  • 【力扣热题100】—— Day3.反转链表
  • 【k8s深入学习之 event 记录】初步了解 k8s event 记录机制
  • redhat 7.9配置阿里云yum源
  • 深入探索Flax:一个用于构建神经网络的灵活和高效库
  • Nginx auth_request详解
  • 基于Java Springboot个人财务APP且微信小程序
  • vue3图片报错转换为空白不显示的方法
  • mysq之快速批量的插入生成数据
  • 浅谈C#库之DevExpress
  • 聊聊Flink:这次把Flink的触发器(Trigger)、移除器(Evictor)讲透
  • 一款支持80+语言,包括:拉丁文、中文、阿拉伯文、梵文等开源OCR库
  • Flink四大基石之CheckPoint(检查点) 的使用详解
  • JVM 常见面试题及解析(2024)
  • Python 调用 Umi-OCR API 批量识别图片/PDF文档数据
  • K8S资源之secret资源
  • QT:信号和槽01
  • 针对Qwen-Agent框架的Function Call及ReAct的源码阅读与解析:Agent基类篇
  • XML 查看器:深入理解与高效使用
  • 《Vue零基础入门教程》第十五课:样式绑定
  • 以AI算力助推转型升级,暴雨亮相CCF中国存储大会
  • 【VMware】Ubuntu 虚拟机硬盘扩容教程(Ubuntu 22.04)
  • 3D Bounce Ball Game 有什么技巧吗?
  • 【SQL】实战--组合两个表
  • Spring基于注解实现 AOP 切面功能
  • 设计模式 更新ing