欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > 记录QT5迁移到QT6.8上的一些问题

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

2025/5/2 14:33:25 来源:https://blog.csdn.net/u011738895/article/details/144110338  浏览:    关键词:记录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)));

后面有啥问题再记录吧

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词