欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > visutal studio 2022使用qcustomplot基础教程

visutal studio 2022使用qcustomplot基础教程

2025/2/23 0:34:30 来源:https://blog.csdn.net/fengyu09/article/details/145645911  浏览:    关键词:visutal studio 2022使用qcustomplot基础教程

编译

下载,2.1.1版支持到Qt6.4 。
拷贝qcustomplot.h和qcustomplot.cpp到项目源目录(Qt project)。

在msvc中将它俩加入项目中。
在这里插入图片描述使用Qt6.8,需要修改两处代码:
L6779

# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)if (mDateTimeSpec == Qt::TimeZone)return locale.toString(keyToDateTime(tick).toTimeZone(mTimeZone), mDateTimeFormat);else if (mDateTimeSpec == Qt::UTC)return locale.toString(keyToDateTime(tick).toUTC(), mDateTimeFormat);else if(mDateTimeSpec == Qt::LocalTime)return locale.toString(keyToDateTime(tick).toLocalTime(), mDateTimeFormat);else {return locale.toString(keyToDateTime(tick).toOffsetFromUtc(0), mDateTimeFormat);}
# elsereturn locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat);
# endif
}

toOffsetFromUtc是凑数的函数调用。

L6894

return date.startOfDay(QTimeZone("Asia/Shanghai")).toMSecsSinceEpoch() / 1000.0;

这里直接用了上海时区。

不改就会报错,qtcostumplt最近最新是2022年。

编辑UI,添加widget,然后做提升:
在这里插入图片描述注:通过Vs开UI编辑,点保存后会自动进行转换。

添加printsupport
在这里插入图片描述不指定qt库路径,会找不到Qt6PrintSupportd.lib,但是它又能找到qtcore它们。
在这里插入图片描述

代码

plot1.h

#pragma once#include <QtWidgets/QMainWindow>
#include "ui_plot1.h"class plot1 : public QMainWindow
{Q_OBJECTpublic:plot1(QWidget *parent = nullptr);~plot1();private:Ui::plot1Class ui;
};

plot1.cpp

#include "plot1.h"plot1::plot1(QWidget *parent): QMainWindow(parent)
{ui.setupUi(this);// generate some data:QVector<double> x(101), y(101); // initialize with entries 0..100for (int i = 0; i < 101; ++i){x[i] = i / 50.0 - 1; // x goes from -1 to 1y[i] = x[i] * x[i]; // let's plot a quadratic function}// create graph and assign data to it:ui.plot->addGraph();ui.plot->graph(0)->setData(x, y);// give the axes some labels:ui.plot->xAxis->setLabel("x轴");ui.plot->yAxis->setLabel("y");// set axes ranges, so we see all data:ui.plot->xAxis->setRange(-1, 1);ui.plot->yAxis->setRange(0, 1);ui.plot->replot();
}plot1::~plot1()
{}

用公式f(x)=x^2,生成100个数据,设定数据源,设定x,y范围,画出抛物线。
在这里插入图片描述

版权声明:

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

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

热搜词