gpt4 book ai didi

c++ - 'setMargin' 中没有名为 'QwtPlotLayout' 的成员 - 将 Qt4.7 转换为 Qt5.8

转载 作者:行者123 更新时间:2023-11-30 03:33:33 25 4
gpt4 key购买 nike

我需要将 Qt 遗留代码从 4.7 转换为 5.8,我在 Qt Creator 4.2.1 Clang 7.0(Apple) 64 位中遇到编译错误。我正在使用最新的 Qwt 6.1.3

在 .cpp 文件中查找

#include "frmMainChart_UI.h"
#include <QHeaderView>
#include <qwt_plot_layout.h>
#include <qwt_legend.h>
#include "mpiDateScale.h"
#include "mpiPercentScale.h"

void frmMainChart_UI::setupUI(QWidget *parent_)
{
frmMainTableViewTree_UI::setupUI(QMap<int, QString>(), false, parent_);
delete frmMainTableViewTree_UI::tableCopy;
delete frmMainTableViewTree_UI::table;

chart = new mpiChart(widget);
chart->setAxisScaleDraw(QwtPlot::xBottom, new mpiDateScale());
chart->setAxisScaleDraw(QwtPlot::yLeft, new mpiPercentScale());
chart->plotLayout()->setCanvasMargin(20);
chart->plotLayout()->setMargin(20); // BROKE convert Qt4 to Qt5
chartZoomer = new mpiPlotZoomer(chart->canvas()); // BROKE convert Qt4 to Qt5
chartLegend = new QwtLegend(chart);
chart->insertLegend(chartLegend, QwtPlot::RightLegend);

QLinearGradient grad(0, 0, 1, 1);
grad.setCoordinateMode(QGradient::StretchToDeviceMode);
grad.setColorAt(0, Qt::white);
grad.setColorAt(1, QColor(220, 220, 220));

.cpp 中有 2 个错误

../src/ui/frmMainChart_UI.cpp:18:26: 错误:“QwtPlotLayout”中没有名为“setMargin”的成员 图表->plotLayout()->setMargin(20);//中断将 Qt4 转换为 Qt5

../src/ui/frmMainChart_UI.cpp:19:23: 错误:'mpiPlotZoomer' 的初始化没有匹配的构造函数 chartZoomer = new mpiPlotZoomer(图表->canvas());//中断将 Qt4 转换为 Qt5

           ^

产生了 5 个警告和 2 个错误make: *** [frmMainChart_UI.o] 错误 106:58:25:进程“/usr/bin/make”退出,代码为 2。构建/部署项目 mypersonalindex 时出错(套件:桌面 Qt 5.8.0 clang 64 位)执行步骤“Make”时06:58:25:耗时:00:01。

Qwt 6.1.3 Docs 有成员函数 http://qwt.sourceforge.net/class_qwt_plot_layout.html

void    setCanvasMargin (int margin, int axis=-1)

但是没有使用成员函数

setMargin

我的 C++ 技能非常有限,您是否看到任何可以将其从 Qt4 转换为 Qt5 的小调整。 ...那么替代品是什么?

查看 mpiChart.h 可能与 canvas() 错误有关

#ifndef MPICHART_H
#define MPICHART_H

#include "qwt_plot.h"

class mpiChart : public QwtPlot
{
Q_OBJECT

public:
mpiChart(QWidget *parent_ = 0):
QwtPlot(parent_)
{}

public slots:
void exportChart();
};

#endif // MPICHART_H

并且查看 mpiPlotZoomer.h 与 canvas() 错误相关

#ifndef MPIPLOTZOOMER_H
#define MPIPLOTZOOMER_H

#include <qwt_plot_zoomer.h>
#include <qwt_plot_canvas.h> // JDL convert Qt4 to Qt5
#include <qwt_compat.h> // JDL convert Qt4 to Qt5

class mpiPlotZoomer: public QwtPlotZoomer
{
public:
mpiPlotZoomer(QwtPlotCanvas *canvas_):
QwtPlotZoomer(canvas_, false)
{
setTrackerMode(AlwaysOn);
}

virtual QwtText trackerText(const QwtDoublePoint &pos_) const;
};

#endif // MPIPLOTZOOMER_H

最佳答案

作为 setMargin在您用于 Qt 4.7 的 Qwt 版本和您用于 5.8 的 Qwt 1.6.3 之间的函数已被删除,您别无选择,只能:

  • 替换setMargin通过 setCanvasMargin 来电如果这符合你的需要
  • 或者,删除 setMargin电话

尝试两者,看看在显示 GUI 时哪一个看起来最好。

对于 canvas()错误,不看mpiChart就很难分辨和 mpiPlotZoomer声明。不过,我会试一试:

canvas()用于返回 QwtPlotCanvas*在过去。对于最新版本的 Qwt,它返回 QWidget* .所以如果你的 mpiPlotZoomer构造函数需要一个 QwtPlotCanvas*作为参数,您必须:

  • 替换mpiPlotZoomer参数类型来自 QwtPlotCanvas*通过 QWidget* .如果写 mpiPlotZoomer 的人可能有用类实际上并没有使用 and QwtPlotCanvas成员/属性(他只能将其用于育儿目的)
  • 或替换mpiPlotZoomer(chart->canvas());通过 mpiPlotZoomer( qobject_cast<QwtPlotCanvas*>( chart->canvas() ) );希望一切顺利。

关于c++ - 'setMargin' 中没有名为 'QwtPlotLayout' 的成员 - 将 Qt4.7 转换为 Qt5.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42765853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com