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

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.kler.cn/a/548171.html

相关文章:

  • C++ 后台开发简历优化指南和如何利用DeepSeek优化简历
  • Python学习心得格式化字符串的format
  • Matlab 机器人 雅可比矩阵
  • Springboot核心:统一异常处理
  • DC-6靶机渗透测试全过程
  • java实现表达式计算
  • Zookeeper(47)如何在Zookeeper中设置节点数据?
  • AI 编程工具—Cursor 进阶篇 数据分析
  • rustdesk远程桌面自建服务器
  • RagFlow部署
  • Java8适配的markdown转换html工具(FlexMark)
  • 【C/C++】C++ Vector容器核心操作指南:增删改查全面解析
  • Qt QCommandLinkButton 总结
  • 图的遍历: 广度优先遍历和深度优先遍历
  • no matching cipher found问题一次解决经历
  • 【数据分享】1929-2024年全球站点的逐日降雪深度数据(Shp\Excel\免费获取)
  • python 查询mongo数据批量插入mysql
  • 【devops】Github Actions Secrets | 如何在Github中设置CI的Secret供CI的yaml使用
  • Redis6.2.6下载和安装
  • 硕成C语言22【一些算法和数组的概念】