【嵌入式——QT】Model/View

news2024/7/6 20:44:59

【嵌入式——QT】Model/View

  • 基本原理
  • 数据模型
  • 视图组件
  • 代理
  • Model/View结构的一些概念
  • QFileSystemModel
  • QStringListModel
  • QStandardItemModel
  • 自定义代理

基本原理

GUI应用程序的一个很重要的功能是由用户在界面上编辑和修改数据,典型的如数据库应用程序,数据库应用程序中,用户在界面上执行各种操作,实际上是修改了界面组件所关联的数据库内的数据。将界面组件与所编辑的数据分离开来,又通过数据源的方式连接起来,是处理界面与数据的一种较好的方式,Qt使用Model/View结构来处理这种关系。

数据模型

QAbstractItemModel

  • QAbstractListModel:QStringListModel,处理字符串列表数据的数据模型类;
  • QAbstractProxyModel:QSortFilterProxyModel,提供排序和过滤功能的数据模型类;
  • QAbstractTableModel:QSqlQueryModel,数据库SQL查询结构的数据模型类;QSqlTableModel,用于数据库的一个数据表的数据模型类;QSqlRelationalTableModel,关系型数据表的数据模型类;
  • QStandardItemModel:每个项数据可以使任何数据类型;
  • QFileSystemModel:文件系统的数据模型类;

视图组件

  • QListView:用于显示单列的列表数据,适用于一维数据的操作;
  • QTreeView:用于显示树状结构数据,适用于树状结构数据的操作;
  • QTableView:用于显示表格状数据,适用于二维表格型数据的操作;
  • QColumnView:用多个QListView显示树状层次结构,树状结构的一层用一个QListView显示;
  • QHeaderView:提供行表头或列表头的视图组件,如QTableView的行表头和列表头;

代理

代理(Delegate)就是在视图组件上为编辑数据提供编辑器,如在表格组件中编辑一个单元格的数据时,缺省是使用一个QLineEdit编辑框。
代理负责从数据模型获取相应的数据,然后显示在编辑器里,修改数据后,又将其保存到数据模型中。
QAbstractItemDelegate是所有代理类的基类,它不能直接使用,它的一个子类QStyledItemDelegate,是Qt的视图组件缺省使用的代理类。

Model/View结构的一些概念

基本结构
数据模型中的存储数据的基本单元都是项(item),每个项都有一个行号,一个列号,还有一个父项。
模型索引
QModelIndex表示模型索引的类,模型索引提供数据存取的一个临时指针,用于通过数据模型提取或修改数据,因为模型内部数据的结构随时可能改变,所以模型索引是临时的。
行号和列号
数据模型的基本形式是用行和列定义的表格数据,要获得一个模型索引,必须提供行号、列号、父项的模型索引。
父项
当数据模型是列表或表格时,使用行号、列号存储数据比较直观,所有数据项的父项就是顶层项,当数据模型是树状结构时,情况比较复杂,一个节点可以有父节点,也可以是其他节点的父节点,在构造数据项的模型索引时,必须指定正确的行号、列号和父节点。
项的角色
在为数据模式的一个项设置数据时,可以赋予其不同项的角色的数据。
enum ItemDataRole

  • Qt::DisplayRole:在视图组件中显示字符串,标准角色;
  • Qt::ToolTipRole:鼠标提示消息;
  • Qt::UserRole:可以自定义数据;

QFileSystemModel

QFileSystemModel提供了一个可用于访问本机文件系统的数据模型,QFileSystemModel和视图组件QTreeView结合使用,可以用目录树的形式显示本机上的文件系统,如同Windows的资源管理器一样,使用QFileSystemModel提供的接口函数,可以创建目录,删除目录,重命名目录,可以获得文件名称、目录名称、文件大小等参数,还可以获得文件的详细信息。
图示
在这里插入图片描述

代码示例
ModelViewDialog.h

#ifndef MODELVIEWDIALOG_H
#define MODELVIEWDIALOG_H

#include <QDialog>
#include <QFileSystemModel>

namespace Ui
{
    class ModelViewDialog;
}

class ModelViewDialog : public QDialog
{
    Q_OBJECT

public:
    explicit ModelViewDialog(QWidget* parent = nullptr);
    ~ModelViewDialog();
private slots:
    void on_treeView_clicked(const QModelIndex& index);

private:
    Ui::ModelViewDialog* ui;

    QFileSystemModel* model;
};

#endif // MODELVIEWDIALOG_H

ModelViewDialog.cpp

#include "ModelViewDialog.h"
#include "ui_ModelViewDialog.h"
ModelViewDialog::ModelViewDialog(QWidget* parent)
    : QDialog(parent)
    , ui(new Ui::ModelViewDialog)
{
    ui->setupUi(this);
    model = new QFileSystemModel(this);
    //QDir::currentPath() 获得本机文件系统
    model->setRootPath(QDir::currentPath());//设置根目录
    ui->treeView->setModel(model);//设置数据模型
    ui->listView->setModel(model);//设置数据模型
    ui->tableView->setModel(model);//设置数据模型
    connect(ui->treeView, SIGNAL(clicked(QModelIndex)), ui->listView, SLOT(setRootIndex(QModelIndex)));
    connect(ui->treeView, SIGNAL(clicked(QModelIndex)), ui->tableView, SLOT(setRootIndex(QModelIndex)));
}

ModelViewDialog::~ModelViewDialog()
{
    delete ui;
}


void ModelViewDialog::on_treeView_clicked(const QModelIndex& index)
{
    ui->checkBox->setChecked(model->isDir(index));//是否目录
    ui->labPath->setText(model->filePath(index));//返回节点的目录名或带路径的文件名
    ui->labType->setText(model->type(index));//返回描述节点类型的文字
    ui->labFileName->setText(model->fileName(index));//返回去除路径的文件夹名称或文件名
    int sz = model->size(index)/1024;//如果节点是文件,返回文件大小的字节数,如果节点是文件夹,返回0
    if(sz<1024) {
        ui->labSize->setText(QString("%1 KB").arg(sz));
    } else {
        ui->labSize->setText(QString::asprintf("%.1f MB", sz/1024.0));
    }
}


QStringListModel

QStringListModel用于处理字符串列表的数据模型,它可以作为QListView的数据模型,在界面上显示和编辑字符串列表。

图示
在这里插入图片描述

代码示例

QStringListModelDialog.h

#ifndef QSTRINGLISTMODELDIALOG_H
#define QSTRINGLISTMODELDIALOG_H

#include <QDialog>
#include <QStringListModel>

namespace Ui
{
    class QStringListModelDialog;
}

class QStringListModelDialog : public QDialog
{
    Q_OBJECT

public:
    explicit QStringListModelDialog(QWidget* parent = nullptr);
    ~QStringListModelDialog();

private slots:
    void on_pushButtonAdd_clicked();

    void on_pushButtonInsert_clicked();

    void on_pushButtonRemove_clicked();

    void on_pushButtonClear_clicked();

    void on_pushButtonShow_clicked();

    void on_listView_clicked(const QModelIndex& index);

    void on_pushButtonReset_clicked();

    void on_pushButtonClearText_clicked();

private:
    Ui::QStringListModelDialog* ui;

    QStringListModel* model;
};

#endif // QSTRINGLISTMODELDIALOG_H

QStringListModelDialog.cpp

#include "QStringListModelDialog.h"
#include "ui_QStringListModelDialog.h"
QStringListModelDialog::QStringListModelDialog(QWidget* parent)
    : QDialog(parent)
    , ui(new Ui::QStringListModelDialog)
{
    ui->setupUi(this);
    QStringList theStrList;
    theStrList<<"北京"<<"上海"<<"天津"<<"河北"<<"河南"<<"山东";
    model = new QStringListModel(this);
    //将一个字符串列表的内容作为数据模型的初始化数据内容
    model->setStringList(theStrList);
    ui->listView->setModel(model);
    //双击 或 选择并单击后进入编辑状态
    ui->listView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
}

QStringListModelDialog::~QStringListModelDialog()
{
    delete ui;
}

void QStringListModelDialog::on_pushButtonAdd_clicked()
{
    model->insertRow(model->rowCount());//在尾部插入一行
    QModelIndex index = model->index(model->rowCount()-1, 0);
    model->setData(index, "new item", Qt::DisplayRole);
    ui->listView->setCurrentIndex(index);//设置当前选中的行
}


void QStringListModelDialog::on_pushButtonInsert_clicked()
{
    QModelIndex index = ui->listView->currentIndex();
    model->insertRow(index.row());
    model->setData(index, "inserted item", Qt::DisplayRole);
    ui->listView->setCurrentIndex(index);
}


void QStringListModelDialog::on_pushButtonRemove_clicked()
{
    QModelIndex index = ui->listView->currentIndex();
    model->removeRow(index.row());
}


void QStringListModelDialog::on_pushButtonClear_clicked()
{
    model->removeRows(0, model->rowCount());
}


void QStringListModelDialog::on_pushButtonShow_clicked()
{
    QStringList tmpList = model->stringList();
    ui->plainTextEdit->clear();
    for(int i=0; i<tmpList.count(); i++) {
        ui->plainTextEdit->appendPlainText(tmpList.at(i));
    }
}


void QStringListModelDialog::on_listView_clicked(const QModelIndex& index)
{
    ui->label->setText(QString::asprintf("current:row=%d,column=%d", index.row(), index.column()));
}


void QStringListModelDialog::on_pushButtonReset_clicked()
{
    model->removeRows(0, model->rowCount());
    QStringList theStrList;
    theStrList<<"北京"<<"上海"<<"天津"<<"河北"<<"河南"<<"山东";
    model->setStringList(theStrList);
}


void QStringListModelDialog::on_pushButtonClearText_clicked()
{
    ui->plainTextEdit->clear();
}

QStandardItemModel

QStandardItemModel是标准的以项数据为基础的标准数据模型类,通常与QTableView组合成Model/View结构。实现通用的二维数据的管理功能。

图示
在这里插入图片描述

代码示例
QStandardItemModelDialog.h

#ifndef QSTANDARDITEMMODELDIALOG_H
#define QSTANDARDITEMMODELDIALOG_H

#include <QDialog>
#include <QLabel>

#include <QStandardItemModel>
#include <QItemSelectionModel>
#define FixedColumnCount 6
namespace Ui
{
    class QStandardItemModelDialog;
}

class QStandardItemModelDialog : public QDialog
{
    Q_OBJECT

public:
    explicit QStandardItemModelDialog(QWidget* parent = nullptr);
    ~QStandardItemModelDialog();

    void initModelFromStringList(QStringList& fFileContent);

public slots:
    void on_currentChanged(const QModelIndex& current, const QModelIndex& previous);


private slots:
    void on_pushButtonOpen_clicked();

    void on_pushButtonAdd_clicked();

    void on_pushButtonInsert_clicked();

    void on_pushButtonRemove_clicked();

    void on_pushButtonLeft_clicked();

    void on_pushButtonMid_clicked();

    void on_pushButtonRight_clicked();

    void on_pushButtonBold_clicked();

    void on_pushButtonSaveAs_clicked();

private:
    Ui::QStandardItemModelDialog* ui;
    QStandardItemModel* model;
    QLabel* labCurFile;
    QLabel* labCellPos;
    QLabel* labCellText;
    QItemSelectionModel* theSelection;


};

#endif // QSTANDARDITEMMODELDIALOG_H

QStandardItemModelDialog.cpp

#include "QStandardItemModelDialog.h"
#include "ui_QStandardItemModelDialog.h"
#include <QAbstractItemView>
#include <QFileDialog>
#include <QTextStream>

QStandardItemModelDialog::QStandardItemModelDialog(QWidget* parent)
    : QDialog(parent)
    , ui(new Ui::QStandardItemModelDialog)
{
    ui->setupUi(this);
    model = new QStandardItemModel(0, FixedColumnCount, this);
    theSelection = new QItemSelectionModel(model);
    connect(theSelection, SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(on_currentChanged(QModelIndex, QModelIndex)));
    ui->tableView->setModel(model);
    ui->tableView->setSelectionModel(theSelection);
    ui->tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
    ui->tableView->setSelectionBehavior(QAbstractItemView::SelectItems);
}

QStandardItemModelDialog::~QStandardItemModelDialog()
{
    delete ui;
}

void QStandardItemModelDialog::initModelFromStringList(QStringList& fFileContent)
{
    int rowCnt = fFileContent.count();
    model->setRowCount(rowCnt);
    QString header = fFileContent.at(0);
    //用一个或多个空白字符分隔  SkipEmptyParts函数会跳过任何空的部分
    QStringList headerList = header.split(QRegExp("\\s+"), QString::SkipEmptyParts);
    model->setHorizontalHeaderLabels(headerList);
    QStandardItem* item;
    QStringList tmpList;
    int j;
    for(int i=1; i<rowCnt; i++) {
        QString aLinText = fFileContent.at(i);
        tmpList = aLinText.split(QRegExp("\\s+"), QString::SkipEmptyParts);
        for(j=0; j<FixedColumnCount-1; j++) {
            item = new QStandardItem(tmpList.at(j));
            model->setItem(i-1, j, item);
        }
        item = new QStandardItem(headerList.at(j));
        item->setCheckable(true);
        if(tmpList.at(j) == "0") {
            item->setCheckState(Qt::Unchecked);
        } else {
            item->setCheckState(Qt::Checked);
        }
        model->setItem(i-1, j, item);
    }
}

void QStandardItemModelDialog::on_currentChanged(const QModelIndex& current, const QModelIndex& previous)
{
    if(current.isValid()) {
        // labCellPos->setText(QString::asprintf("current: row=%d , col=%d", current.row(), current.column()));
        QStandardItem* item = model->itemFromIndex(current);
        // this->labCellText->setText("text:"+item->text());
        // QFont font = item->font();
    }
}

void QStandardItemModelDialog::on_pushButtonOpen_clicked()
{
    QString curPath = QCoreApplication::applicationDirPath();
    QString aFileName = QFileDialog::getOpenFileName(this, u8"打开文件", curPath);
    if(aFileName.isEmpty()) {
        return;
    }
    QStringList fFileContent;
    QFile afile(aFileName);
    if(afile.open(QIODevice::ReadOnly |QIODevice::Text)) {
        QTextStream aStream(&afile);
        ui->plainTextEdit->clear();
        while(!aStream.atEnd()) {
            QString str = aStream.readLine();
            ui->plainTextEdit->appendPlainText(str);
            fFileContent.append(str);
        }
        afile.close();
        // labCurFile->setText("currentFile:"+aFileName);
        initModelFromStringList(fFileContent);
    }
}


void QStandardItemModelDialog::on_pushButtonAdd_clicked()
{
    QList<QStandardItem*> itemList;
    QStandardItem* item;
    //不包含最后一列
    for(int i=0; i<FixedColumnCount-1; i++) {
        item = new QStandardItem("0");
        // item->setCheckable(true);
        itemList<<item;
    }
    QString str = model->headerData(model->columnCount()-1, Qt::Horizontal, Qt::DisplayRole).toString();
    item = new QStandardItem(str);
    item->setCheckable(true);
    itemList<<item;
    model->insertRow(model->rowCount(), itemList);
    QModelIndex curIndex = model->index(model->rowCount()-1, 0);
    theSelection->clearSelection();
    theSelection->setCurrentIndex(curIndex, QItemSelectionModel::Select);
}


void QStandardItemModelDialog::on_pushButtonInsert_clicked()
{
    QList<QStandardItem*> itemList;
    QStandardItem* item;
    //不包含最后一列
    for(int i=0; i<FixedColumnCount-1; i++) {
        item = new QStandardItem("0");
        // item->setCheckable(true);
        itemList<<item;
    }
    QString str = model->headerData(model->columnCount()-1, Qt::Horizontal, Qt::DisplayRole).toString();
    item = new QStandardItem(str);
    item->setCheckable(true);
    itemList<<item;
    QModelIndex curIndex = theSelection->currentIndex();
    int curRow = curIndex.row();
    model->insertRow(curRow, itemList);
    curIndex = model->index(curRow, 0);
    theSelection->clearSelection();
    theSelection->setCurrentIndex(curIndex, QItemSelectionModel::Select);
}


void QStandardItemModelDialog::on_pushButtonRemove_clicked()
{
    QModelIndex curIndex = theSelection->currentIndex();
    if(curIndex.row() == model->rowCount()-1) {
        model->removeRow(curIndex.row());
    } else {
        model->removeRow(curIndex.row());
        theSelection->setCurrentIndex(curIndex, QItemSelectionModel::Select);
    }
}


void QStandardItemModelDialog::on_pushButtonLeft_clicked()
{
    if(!theSelection->hasSelection()) {
        return;
    }
    QModelIndexList selectedIndex = theSelection->selectedIndexes();
    for(int i=0; i<selectedIndex.count(); i++) {
        QModelIndex aIndex = selectedIndex.at(i);
        QStandardItem* item = model->itemFromIndex(aIndex);
        item->setTextAlignment(Qt::AlignLeft);
    }
}


void QStandardItemModelDialog::on_pushButtonMid_clicked()
{
    if(!theSelection->hasSelection()) {
        return;
    }
    QModelIndexList selectedIndex = theSelection->selectedIndexes();
    for(int i=0; i<selectedIndex.count(); i++) {
        QModelIndex aIndex = selectedIndex.at(i);
        QStandardItem* item = model->itemFromIndex(aIndex);
        item->setTextAlignment(Qt::AlignCenter);
    }
}


void QStandardItemModelDialog::on_pushButtonRight_clicked()
{
    if(!theSelection->hasSelection()) {
        return;
    }
    QModelIndexList selectedIndex = theSelection->selectedIndexes();
    for(int i=0; i<selectedIndex.count(); i++) {
        QModelIndex aIndex = selectedIndex.at(i);
        QStandardItem* item = model->itemFromIndex(aIndex);
        item->setTextAlignment(Qt::AlignRight);
    }
}


void QStandardItemModelDialog::on_pushButtonBold_clicked()
{
    if(!theSelection->hasSelection()) {
        return;
    }
    QModelIndexList selectedIndex = theSelection->selectedIndexes();
    for(int i=0; i<selectedIndex.count(); i++) {
        QModelIndex aIndex = selectedIndex.at(i);
        QStandardItem* item = model->itemFromIndex(aIndex);
        QFont font = item->font();
        font.setBold(Qt::Checked);
        item->setFont(font);
    }
}


void QStandardItemModelDialog::on_pushButtonSaveAs_clicked()
{
    QString curPath = QCoreApplication::applicationDirPath();
    QString aFileName = QFileDialog::getSaveFileName(this, u8"选择一个文件", curPath);
    if(aFileName.isEmpty()) {
        return;
    }
    QFile file(aFileName);
    if(!(file.open(QIODevice::ReadWrite | QIODevice::Text| QIODevice::Truncate))) {
        return;
    }
    QTextStream aStream(&file);
    QStandardItem* item;
    int i, j;
    QString str;
    ui->plainTextEdit->clear();
    for(int i=0; i<model->columnCount(); i++) {
        item = model->horizontalHeaderItem(i);
        str = str +item->text()+"\t\t";
    }
    aStream<<str<<"\n";
    ui->plainTextEdit->appendPlainText(str);
    for(i=0; i<model->rowCount(); i++) {
        str="";
        for(j=0; j<model->columnCount()-1; j++) {
            item = model->item(i, j);
            str=str+item->text()+QString::asprintf("\t\t");
        }
        item = model->item(i, j);
        if(item->checkState() == Qt::Checked) {
            str = str+"1";
        } else {
            str = str+"0";
        }
        ui->plainTextEdit->appendPlainText(str);
        aStream<<str<<"\n";
    }
}


自定义代理

QAbstractItemDelegate是所有代理类的抽象基类,QStyledItemDelegate是视图组件使用的缺省的代理类,QItemDelegate也是类似功能的类。
QStyledItemDelegate和QItemDelegate的差别在于前者可以使用样式表设置来绘制组件,因此建议使用QStyledItemDelegate作为自定义代理类组件的基类。
无论从QStyledItemDelegate还是QItemDelegate继承设计自定义代理组件,都会必须实现这四个函数。

  1. createEditor:创建用于编辑模型数据的widget组件,如QSpinBox组件;
  2. setEditorData:从数据模型获取数据,供widget组件进行编辑;
  3. setModelData:将widget上的数据更新到数据模型;
  4. updateEditorGeometry:用于给widget组件设置一个合适的大小;

详见我之前一段时间所写的文章 文章地址

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1500184.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

leetcode刷题(javaScript)——字典哈希表相关场景题总结

在 JavaScript 刷题中&#xff0c;字典&#xff08;Dictionary&#xff09;和哈希表&#xff08;Hash Table&#xff09;通常用来存储键值对&#xff0c;提供快速的查找、插入和删除操作。它们在很多算法题目中都有广泛的应用&#xff0c;特别是在需要快速查找元素或统计元素出…

Unity插件之天气系统UniStorm

首先呢&#xff0c;它是一款强大的动态昼夜天气系统&#xff0c;能够以较快的帧速率创建AAA级动态生成的天气、照明和天空&#xff0c;并且具有300多个可定制的组件&#xff0c;允许用户创建任何可以想象的环境。 第一步&#xff1a;他需要两个物体Camera摄像机、Player播放器…

用于回归的概率模型

机器学习中的回归方法&#xff1a; 机器学习中的概率模型 机器学习&#xff5c;总结了11种非线性回归模型&#xff08;理论代码可视化&#xff09; 高斯过程回归&#xff1a; Gaussian Processes for Machine Learning GPML——Datasets and Code Gaussian Processes 学…

淘宝商品详情数据丨商品搬家丨商品采集丨商城建站

淘宝商品详情数据、商品搬家、商品采集以及商城建站都是电子商务领域的重要环节&#xff0c;它们共同构成了一个完整的在线销售体系。下面我将分别对这几个概念进行详细的解释。 请求示例&#xff0c;API接口接入Anzexi58 一、淘宝商品详情数据 淘宝商品详情数据指的是在淘宝…

react native封装ScrollView,实现(滑到底部)和(滑到顶部+手指继续向下滑)时拉取新数据

里面的tw是在react native中使用tailwind的第三方库 只求读者把样式看个大概&#xff0c;主要还是功能的实现 ScrollView的官方文档如下 https://reactnative.cn/docs/scrollview import tw from twrnc import { View, Text, ScrollView, RefreshControl } from react-native …

LED显示控制芯片SM5166PF:可消除LED显示屏拖影

在数字化时代的浪潮下&#xff0c;LED显示屏作为信息传播的重要媒介&#xff0c;其显示质量和效果日益受到人们的关注。尤其在商业广告、体育赛事、公共信息发布等领域&#xff0c;高清、流畅、稳定的显示效果显得尤为重要。然而&#xff0c;传统的LED显示屏在刷新率和显示效果…

金智维售前总监屈文浩,将出席“ISIG-RPA超级自动化产业发展峰会”

3月16日&#xff0c;第四届「ISIG中国产业智能大会」将在上海中庚聚龙酒店拉开序幕。本届大会由苏州市金融科技协会指导&#xff0c;企智未来科技&#xff08;RPA中国、AIGC开放社区、LowCode低码时代&#xff09;主办。大会旨在聚合每一位产业成员的力量&#xff0c;深入探索R…

在Linux以命令行方式(静默方式/非图形化方式)安装MATLAB(正版)

1.根据教程&#xff0c;下载windows版本matlab&#xff0c;打开图形化界面&#xff0c;选择linux版本的只下载不安装 2.获取安装文件夹 3.获取许可证 4.安装 &#xff08;1&#xff09;跳过引用文章的2.2章节 &#xff08;2&#xff09;本文的安装文件夹代替引用文章的解压IS…

使用Julia语言及R语言进行格拉布斯检验

在日常的计量检测工作中经常会处理各种数据&#xff0c;在处理数据之前会提前使用格拉布斯准则查看数据中是否存在异常值&#xff0c;如果存在异常值的话应该重新进行计量检测&#xff0c;没有异常值则对数据进行下一步操作。判断异常值常用的格拉布斯方法基于数据来自正态分布…

【leetcode热题】环形链表 II

难度&#xff1a; 中等通过率&#xff1a; 30.1%题目链接&#xff1a;. - 力扣&#xff08;LeetCode&#xff09; 题目描述 给定一个链表&#xff0c;返回链表开始入环的第一个节点。 如果链表无环&#xff0c;则返回 null。 为了表示给定链表中的环&#xff0c;我们使用整数…

SqlServer 默认值约束示例

创建表&#xff0c;创建时指定 money 字段默认值为0.00&#xff1b; create table t_24 ( account varchar(19) not null, id_card char(18) not null, name varchar(20) not null, money decimal(16,2) default 0.00 not null ); 录入2条记录&#xff0c;money字…

Windows Docker 部署 MySQL

部署 MySQL 打开 Docker Desktop&#xff0c;切换到 Linux 容器。然后在 PowerShell 执行下面命令&#xff0c;即可启动一个 MySQL 服务。这里安装的是 8.3.0 Tag版本&#xff0c;如果需要安装其他或者最新版本&#xff0c;可以到 Docker Hub 进行查找。 docker run -itd --n…

在微信小程序里的ecahrts图表,tooltip中内容有黑色阴影的问题

tooltip并没有设置文字阴影相关配置&#xff0c;但是实际真机测试出来有黑色阴影&#xff08;本地编译器没有阴影&#xff09;&#xff0c; 经过研究发现&#xff0c;需要在tooltip中加上以下配置就OK了 tooltip: {// .....textStyle:{textShadowColor:transparent,//文字块背景…

go|一道算法题引发的思考|slice底层剖析

文章目录 引发思考的一道算法题slicemake初始化切片扩容原理切片截取原理切片复制原理算法题的正解 补充string和[]byte互转string 与[]byte相互转换 引发思考的一道算法题 链接&#xff1a;组合 给定两个整数 n 和 k&#xff0c;返回 1 … n 中所有可能的 k 个数的组合。 大致…

处理error: remote origin already exists.及其Gitee文件上传保姆级教程

解决error: remote origin already exists.&#xff1a; 删除远程 Git 仓库 git remote rm origin 再添加远程 Git 仓库 git remote add origin &#xff08;HTTPS&#xff09; 比如这样&#xff1a; 然后再push过去就ok了 好多人可能还是不熟悉怎么将文件上传 Gitee:我…

Unity零基础到进阶 | Unity中 屏蔽指定UI点击事件 的多种方法整理

Unity零基础到进阶 | Unity中 屏蔽指定UI点击事件 的多种方法整理一、Unity中 屏蔽透明区域的点击事件1.1 使用Image组件自带的参数检测1.2 根据点击的坐标计算该点的像素值是否满足阈值 二、Unity中屏蔽 不规则图片按钮点击的事件 总结 &#x1f3ac; 博客主页&#xff1a;htt…

LInux-多线程基础概念

文章目录 前言预备页表详解缺页中断页表的映射 一、多线程是什么&#xff1f;轻量级进程 二、Pthread库pthread_create 前言 从本章的多线程开始&#xff0c;我们开始进入Linux系统的尾声&#xff0c;所以&#xff0c;在学习多线程的过程中&#xff0c;我们也会逐步对之前的内…

Spring基础——Spring配置Mybatis连接数据库

目录 Spring配置MyBatis流程1. 添加Mybatis依赖2. 配置MySQL数据库连接池2.1 首先创建jdbc配置文件2.2 配置数据库DataSource 3. 配置MyBatis3.1 配置SqlSessionFactoryBean3.2 配置mybatis Mapper Bean 4. 创建MyBatis Mapper接口6. 测试数据输出 数据库类型&#xff1a;MySQL…

centos7虚拟机启动并配置java环境(vmware启动+安装jdk+安装maven)

VMware下载 推荐很详细的一个教程Centos7.7安装及配置教程 - 掘金 VMware下载链接&#xff1a;https://pan.baidu.com/s/1jnUBawBPOtAD0gicZj-qTA?pwdm959 提取码&#xff1a;m959 centos7镜像&#xff08;文件较大&#xff0c;建议使用迅雷&#xff0c;更好支持暂停后继续下…

(MATLAB)应用实例13-时域信号的频谱分析

采用傅里叶变换来计算存在噪声的适于信号频谱。 假设数据采样频率为1000Hz&#xff0c;一个信号包含两个正弦波&#xff0c;频率50Hz、120Hz&#xff0c;振幅0.7、1&#xff0c;噪声为零平均值的随机噪声&#xff0c;采用FFT方法分析其频谱。 clearFs 1000; …