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

No member named 'setMargin' in 'QwtPlotLayout' - Convert Qt4.7 to Qt5.8

本文关键字:Qt4 Qt5 转换 setMargin QwtPlotLayout 成员      更新时间:2023-10-16

我需要将QT遗产代码从4.7转换为5.8 ,我在QT Creator 4.2.1 Clang 7.0(Apple)64bit中有一个汇编错误。我正在使用最新的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'in'qwtplotlayout' no note 图表 -> plotlayout() -> setMargin(20);//将QT4转换为QT5

../src/ui/frmmainchart_ui.cpp:19:23:错误:没有用于初始化'mpiplotzoomer'的匹配构造函数 ChartZoomer =新的mpiplotzoomer(Chart-> Canvas());//将QT4转换为QT5

           ^

5个警告和2个错误生成制作:*** [frmmainchart_ui.o]错误106:58:25:"/usr/bin/make"的过程被代码2退出。构建/部署项目mypersonalindex时的错误(套件:桌面QT 5.8.0 clang 64bit)执行步骤时"制作"06:58:25:过去的时间:00:01。

QWT 6.1.3 DOCS 具有成员函数http://qwt.sourceforge.net/class_qwt_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

,由于您使用的QT 4.7和QWT 1.6.3在使用5.8的QWT版本之间删除了setMargin函数,因此您别无选择:

  • 如果适合您的需求,请替换 setMargin setCanvasMargin调用
  • 或删除setMargin调用

尝试两者,然后在显示GUI时看起来最好。

对于canvas()错误,很难不看到mpiChartmpiPlotZoomer声明。但是,我会尝试一下:

canvas()过去返回QwtPlotCanvas*。对于QWT的最新版本,它返回QWidget*。因此,如果您的mpiPlotZoomer构造函数期望QwtPlotCanvas*作为参数,则必须:

  • QWidget*替换QwtPlotCanvas*mpiPlotZoomer参数类型。如果编写mpiPlotZoomer类的人实际上不使用和QwtPlotCanvas成员/属性(他只能将其用于育儿目的)
  • 或用mpiPlotZoomer( qobject_cast<QwtPlotCanvas*>( chart->canvas() ) );替换mpiPlotZoomer(chart->canvas());,它可以正常工作。