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

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);
		}
# else
		return 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_OBJECT

public:
    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..100
    for (int i = 0; i < 101; ++i)
    {
        x[i] = i / 50.0 - 1; // x goes from -1 to 1
        y[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范围,画出抛物线。
在这里插入图片描述

http://www.dtcms.com/a/18864.html

相关文章:

  • ROS2 话题通信
  • 算法题(68):路径总和
  • 算法244(力扣136)反转字符串
  • mysql和minio
  • C语言中的文件
  • YOLOV8的学习记录(三) 训练各种模型所使用的数据格式区别
  • Farewell Go,Hello AI:是时候说再见了
  • AWS Fargate 部署流程图及说明
  • 劳力士(Rolex):蚝式恒动(Oyster Perpetual),潜航者(Submariner)和宇宙计型迪通拿(Daytona)中英双语
  • Vue.js 配置 Babel、Webpack 和 ESLint
  • 矩阵碰一碰发视频技术开发全解析,支持OEM
  • 抖去推与超级编导矩阵系统技术深度对比,矩阵系统支持OEM
  • 【Qt】之【Linux】linux下实现开机自启Qt应用程序
  • Golang面试题一
  • promise捕获错误的方式
  • 网络安全-攻击流程-传输层
  • OceanBase使用ob-loader-dumper导出表报ORA-00600
  • 【DeepSeek】本地PC部署和运行DeepSeek-R1-70b
  • 人工智能知识架构详解
  • 自学Java-面向对象高级(final、单例类、枚举类、抽象类、接口)
  • Leetcode 146 LRU缓存 的三种解法
  • 基于Ollama安装deepseek-r1模型搭建本地知识库(Dify、MaxKb、Open-WebUi、AnythingLLM)
  • 算法1-1 玩具谜题
  • FreeBSD系统使用pyenv安装不同版本python,比如python3.12
  • win11 labelme 汉化菜单
  • 集成测试总结文档
  • JMeter工具介绍、元件和组件的介绍
  • 【复现DeepSeek-R1之Open R1实战】系列1:跑通SFT(一步步操作,手把手教学)
  • Python有哪些应用场景
  • 等距节点插值公式