Qt 文件的操作以及实现的文件的复制操作并且在相应的目的地创建文件

2024-03-10 02:20

本文主要是介绍Qt 文件的操作以及实现的文件的复制操作并且在相应的目的地创建文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

最近想做一个局域网的图书管理的一个应用,希望能够管理本地的电子书资源,同时分享给在同一个局域网的用户们。因此在本地需要建立一个图书的管理目录出来(暂时是这样想的),因此需要对电脑上的资源进行统一的移动和复制,同时将可能以后需要的信息进行保存下来,在Qt中可能设计到相关内容的包含:

  • QFile 的使用
  • QDir 的使用
  • QFileInfo的使用
  • QFileDialog的使用
QFile类提供了读取文件和操作文件的接口,可以读写文本文件以及二进制文件,以及资源文件。通常常用的函数包含open()close()函数的使用。

QDir类使得可以访问目录结构以及目录下的文件信息。可以操作路径名、访问路径以及文件的相关信息。可以通过mkdir()创建目录以及重命名目录。

QFileInfo类可以提供与操作系统无关的文件信息,包含文件的名称和文件系统的位置,文件的访问权限以及是否是一个目录。可以通过函数path()fileName()获取文件的路径和文件名,同时baseName()可以获得文件的基本名称,即不包含后缀名。

下面一个简单的实例,可以通过选择需要复制的文件,复制到相应的目录下。同时根据文件名,在相应的目录下创建对应文件的子目录。实现的是,在一个界面进行文件的操作,包括录入图书的信息,包括书名,作者以及出版商,以及书的封面,然后保存。

头文件内容为:

[cpp] view plain copy
print ?
  1. #ifndef UPLOADFRAME_H  
  2. #define UPLOADFRAME_H  
  3.   
  4. #include <QWidget>  
  5. #include<QFrame>  
  6. class QLabel;  
  7. class QIcon;  
  8. class QPushButton;  
  9. class QLineEdit;  
  10. class QTextBrower;  
  11. class QToolButton;  
  12. class UpLoadFrame : public QWidget  
  13. {  
  14.     Q_OBJECT  
  15. public:  
  16.     explicit UpLoadFrame(QWidget *parent = 0);  
  17.     void init();  
  18.     QString getWritername();  
  19.     QString getBookname();  
  20.     QString getPublisername();  
  21.     QString getAboutBook();  
  22.     QPixmap getBookfage();  
  23. signals:  
  24.   
  25. protected slots:  
  26.     void doChoosepathbutton();  
  27.     void doSaveButton();  
  28.     void doBookFaceClicked();  
  29.   
  30. private:  
  31.     QLineEdit *filepath;  
  32.     QPushButton *choosepath;  
  33.     QToolButton *bookface;  
  34.     QLineEdit *writername;  
  35.     QLineEdit *publisher;  
  36.     QLineEdit *bookname;  
  37.     QLineEdit *aboutbook;  
  38.     QPushButton *saveButton;  
  39.     QString fileName;  
  40.     QString picpath;  
  41. };  
  42.   
  43. #endif // UPLOADFRAME_H  
#ifndef UPLOADFRAME_H

define UPLOADFRAME_H

include <QWidget>

include<QFrame>

class QLabel;
class QIcon;
class QPushButton;
class QLineEdit;
class QTextBrower;
class QToolButton;
class UpLoadFrame : public QWidget
{
Q_OBJECT
public:
explicit UpLoadFrame(QWidget *parent = 0);
void init();
QString getWritername();
QString getBookname();
QString getPublisername();
QString getAboutBook();
QPixmap getBookfage();
signals:

protected slots:
void doChoosepathbutton();
void doSaveButton();
void doBookFaceClicked();

private:
QLineEdit *filepath;
QPushButton *choosepath;
QToolButton *bookface;
QLineEdit *writername;
QLineEdit *publisher;
QLineEdit *bookname;
QLineEdit *aboutbook;
QPushButton *saveButton;
QString fileName;
QString picpath;
};

endif // UPLOADFRAME_H

重点是实现三个槽。首先是第一个槽,doChoosepathbutton(),通过店家choosepath按键,打开一个选择文件的对话框选择文件,在该函数中实现文件路径的读取,通过文件的读取,自动设置书名。实现内容如下:

[cpp] view plain copy
print ?
  1. void UpLoadFrame::doChoosepathbutton()  
  2. {  
  3.     fileName =QFileDialog::getOpenFileName(this,tr(“打开文件”));  
  4.     filepath->setText(fileName);  
  5.     QFileInfo info(fileName);  
  6.     bookname->setText(info.baseName());  
  7. }  
void UpLoadFrame::doChoosepathbutton()
{fileName =QFileDialog::getOpenFileName(this,tr("打开文件"));filepath->setText(fileName);QFileInfo info(fileName);bookname->setText(info.baseName());
}
其中一个关键的只是点是关于QFileDialog的知识点:

QFileDialog可以创建一个对话框,允许用于选择文件和目录。getOpenFileName()函数可以选择一个已经存在于目录下的文件,如果取消了文件的选择,就会返回已给空的指针。第一个参数代表父空间的指针地址,第二个是代表对话框的名称。

其次是实现doSaveButton(),当得到需要复制的文件后,就需要比较负责的文件操作了,比如文件的复制,目录的创建以及文本文件的信息的写入。以下是实现的内容:

[cpp] view plain copy
print ?
  1. void UpLoadFrame::doSaveButton()  
  2. {  
  3.     QFile file(fileName);  
  4.     QFileInfo info(fileName);  
  5.     QString newpath=QString(”G:/Reader_Resource”)+QString(“/”);  
  6.   
  7.    //————————创建对应书籍的目录————————//  
  8.     QDir dir;  
  9.     dir.cd(newpath);  
  10.     dir.mkdir(info.baseName());  
  11.     newpath+=info.baseName();  
  12.     //—————-读取图书的信息并保存在对应的目录下—————–//  
  13.   
  14.   
  15.     QFile bookinfo(newpath+”/”+info.baseName()+“.txt”);  
  16.     QFileInfo tmp(bookinfo);  
  17.     aboutbook->setText(tmp.absoluteFilePath());  
  18.     if( bookinfo.open(QFile::ReadWrite))  
  19.     {  
  20.   
  21.         QTextStream out(&bookinfo);  
  22.         out<<writername->text()<<”\r\n”<<endl;  
  23.         out<<bookname->text()<<”\r\n”<<endl;  
  24.         out<<publisher->text()<<”\r\n”<<endl;  
  25.     }  
  26.   
  27.     bookinfo.setFileName(info.baseName()+”.txt”);  
  28.     bookinfo.close();  
  29.     //————————————————————–//  
  30.   
  31.   
  32.     newpath+=QString(”/”);  
  33.   
  34.     //———————-复制图片封面信息————————//  
  35.     QFile picfile(picpath);  
  36.     QFileInfo picinfo(picfile);  
  37.     QString temptopicpath=newpath;  
  38.     temptopicpath+=picinfo.fileName();  
  39.     picfile.copy(temptopicpath);  
  40.     picfile.close();  
  41.   
  42.     //————————-复制文件到相应目录————————//  
  43.     newpath+=info.fileName();  
  44.     file.copy(newpath);  
  45.     file.close();  
  46.   
  47.   
  48.   
  49.     QFile checkpath(newpath);  
  50.     if(checkpath.open(QFile::ReadOnly))  
  51.     {  
  52.         QMessageBox msgBox;  
  53.         msgBox.setText(”文件复制成功”);  
  54.         msgBox.setStandardButtons(QMessageBox::Ok);  
  55.         msgBox.exec();  
  56.     }  
  57.     checkpath.close();  
  58.   
  59. }  
void UpLoadFrame::doSaveButton()
{QFile file(fileName);QFileInfo info(fileName);QString newpath=QString("G:/Reader_Resource")+QString("/");//------------------------创建对应书籍的目录------------------------//QDir dir;dir.cd(newpath);dir.mkdir(info.baseName());newpath+=info.baseName();//----------------读取图书的信息并保存在对应的目录下-----------------//QFile bookinfo(newpath+"/"+info.baseName()+".txt");QFileInfo tmp(bookinfo);aboutbook->setText(tmp.absoluteFilePath());if( bookinfo.open(QFile::ReadWrite)){QTextStream out(&bookinfo);out<<writername->text()<<"\r\n"<<endl;out<<bookname->text()<<"\r\n"<<endl;out<<publisher->text()<<"\r\n"<<endl;}bookinfo.setFileName(info.baseName()+".txt");bookinfo.close();//--------------------------------------------------------------//newpath+=QString("/");//----------------------复制图片封面信息------------------------//QFile picfile(picpath);QFileInfo picinfo(picfile);QString temptopicpath=newpath;temptopicpath+=picinfo.fileName();picfile.copy(temptopicpath);picfile.close();//-------------------------复制文件到相应目录------------------------//newpath+=info.fileName();file.copy(newpath);file.close();QFile checkpath(newpath);if(checkpath.open(QFile::ReadOnly)){QMessageBox msgBox;msgBox.setText("文件复制成功");msgBox.setStandardButtons(QMessageBox::Ok);msgBox.exec();}checkpath.close();}
对以上的代码实现进行简答的解释:

1、对doChoopathbutton()函数中得到的fileName进行文件的读取,即QFile(fileName);

2、对fileName进行文件信息的解析,即通过QFileInfo实现;

3、在对应的newpath下目录下创建目录,目录名为需要复制的文件的文件名,不包含后缀名,这里文件名默认为书名

4、bookinfo是对书名、作者以及出版商信息的读取,并且写入到文本文件中;

5、copy函数是实现文件的复制的关键函数,QFile类的成员函数copy()的参数代表需要复制的新的文件的绝对路径信息。

最后实现的结果如图所示:



可以看到,最后实现了需要达到的目。

完成的实现代码如下:

[cpp] view plain copy
print ?
  1. #include “uploadframe.h”  
  2. #include<QLabel>  
  3. #include<QIcon>  
  4. #include<QLineEdit>  
  5. #include<QPushButton>  
  6. #include<QTextBrowser>  
  7. #include<QToolButton>  
  8. #include<QHBoxLayout>  
  9. #include<QVBoxLayout>  
  10. #include<QFile>  
  11. #include<QFIleDialog>  
  12. #include<QFileInfo>  
  13. #include<QMessageBox>  
  14. #include<QDir>  
  15. #include<QTextStream>  
  16. UpLoadFrame::UpLoadFrame(QWidget *parent) : QWidget(parent)  
  17. {  
  18.   
  19.     filepath=new QLineEdit(this);  
  20.     choosepath=new QPushButton(this);  
  21.     bookface=new QToolButton();  
  22.     writername=new QLineEdit(this);  
  23.     publisher=new QLineEdit(this);  
  24.     bookname=new QLineEdit(this);  
  25.     aboutbook=new QLineEdit(this);  
  26.     init();  
  27.     connect(choosepath,SIGNAL(clicked(bool)),this,SLOT(doChoosepathbutton()));  
  28.     connect(saveButton,SIGNAL(clicked(bool)),this,SLOT(doSaveButton()));  
  29.     connect(bookface,SIGNAL(clicked(bool)),this,SLOT(doBookFaceClicked()));  
  30.     setFixedSize(400,300);  
  31. }  
  32.   
  33. void UpLoadFrame::init()  
  34. {  
  35.     QVBoxLayout *mainLayout=new QVBoxLayout(this);  
  36.     QHBoxLayout *hLayout_one=new QHBoxLayout(this);  
  37.   
  38.     filepath->setMinimumSize(250,20);  
  39.     filepath->setMaximumSize(250,20);  
  40.     filepath->setContentsMargins(0,0,0,0);  
  41.     choosepath->setText(”选择文件”);  
  42.     choosepath->setMaximumHeight(30);  
  43.     choosepath->setMinimumHeight(30);  
  44.     choosepath->setContentsMargins(0,0,0,0);  
  45.   
  46.     hLayout_one->addWidget(filepath);  
  47.     hLayout_one->addStretch();  
  48.     hLayout_one->addWidget(choosepath);  
  49.     hLayout_one->setContentsMargins(0,0,0,0);  
  50.   
  51.     QHBoxLayout *hLayout_two=new QHBoxLayout(this);  
  52.   
  53.     bookface->setIconSize(QSize(150,150));  
  54.   
  55.     QVBoxLayout *vLayout_bookinfo=new QVBoxLayout(this);  
  56.   
  57.     QHBoxLayout *hLayout_two_one=new QHBoxLayout(this);  
  58.     QLabel *static_writer=new QLabel(“作者”,this);  
  59.     writername->setFixedSize(100,30);  
  60.     hLayout_two_one->addWidget(static_writer);  
  61.     hLayout_two_one->addStretch();  
  62.     hLayout_two_one->addWidget(writername);  
  63.   
  64.   
  65.     QHBoxLayout *hLayout_two_two=new QHBoxLayout(this);  
  66.     QLabel *static_bookname=new QLabel(“书名”,this);  
  67.     bookname->setFixedSize(100,30);  
  68.     hLayout_two_two->addWidget(static_bookname);  
  69.     hLayout_two_two->addStretch();  
  70.     hLayout_two_two->addWidget(bookname);  
  71.   
  72.     QHBoxLayout *hLayout_two_three=new QHBoxLayout(this);  
  73.     QLabel *static_publisher=new QLabel(“出版社”,this);  
  74.     publisher->setFixedSize(100,30);  
  75.     hLayout_two_three->addWidget(static_publisher);  
  76.     hLayout_two_three->addStretch();  
  77.     hLayout_two_three->addWidget(publisher);  
  78.   
  79.   
  80.     vLayout_bookinfo->addLayout(hLayout_two_one);  
  81.     vLayout_bookinfo->addLayout(hLayout_two_two);  
  82.     vLayout_bookinfo->addLayout(hLayout_two_three);  
  83.   
  84.     hLayout_two->addWidget(bookface);  
  85.     hLayout_two->addStretch();  
  86.     hLayout_two->addLayout(vLayout_bookinfo);  
  87.   
  88.     aboutbook =new QLineEdit(this);  
  89.     saveButton=new QPushButton(this);  
  90.     saveButton->setText(”保存文件”);  
  91.     saveButton->setMinimumWidth(this->width()*0.8);  
  92.     mainLayout->addLayout(hLayout_one);  
  93.     mainLayout->addStretch();  
  94.     mainLayout->addLayout(hLayout_two);  
  95.     mainLayout->addWidget(saveButton);  
  96.     mainLayout->addWidget(aboutbook);  
  97.     setLayout(mainLayout);  
  98.   
  99.   
  100.   
  101. }  
  102.   
  103. void UpLoadFrame::doChoosepathbutton()  
  104. {  
  105.     fileName =QFileDialog::getOpenFileName(this,tr(“打开文件”));  
  106.     filepath->setText(fileName);  
  107.     QFileInfo info(fileName);  
  108.     bookname->setText(info.baseName());  
  109. }  
  110.   
  111. void UpLoadFrame::doSaveButton()  
  112. {  
  113.     QFile file(fileName);  
  114.     QFileInfo info(fileName);  
  115.     QString newpath=QString(”G:/Reader_Resource”)+QString(“/”);  
  116.   
  117.    //————————创建对应书籍的目录————————//  
  118.     QDir dir;  
  119.     dir.cd(newpath);  
  120.     dir.mkdir(info.baseName());  
  121.     newpath+=info.baseName();  
  122.     //—————-读取图书的信息并保存在对应的目录下—————–//  
  123.   
  124.   
  125.     QFile bookinfo(newpath+”/”+info.baseName()+“.txt”);  
  126.     QFileInfo tmp(bookinfo);  
  127.     aboutbook->setText(tmp.absoluteFilePath());  
  128.     if( bookinfo.open(QFile::ReadWrite))  
  129.     {  
  130.   
  131.         QTextStream out(&bookinfo);  
  132.         out<<writername->text()<<”\r\n”<<endl;  
  133.         out<<bookname->text()<<”\r\n”<<endl;  
  134.         out<<publisher->text()<<”\r\n”<<endl;  
  135.     }  
  136.   
  137.     bookinfo.setFileName(info.baseName()+”.txt”);  
  138.     bookinfo.close();  
  139.     //————————————————————–//  
  140.   
  141.   
  142.     newpath+=QString(”/”);  
  143.   
  144.     //———————-复制图片封面信息————————//  
  145.     QFile picfile(picpath);  
  146.     QFileInfo picinfo(picfile);  
  147.     QString temptopicpath=newpath;  
  148.     temptopicpath+=picinfo.fileName();  
  149.     picfile.copy(temptopicpath);  
  150.     picfile.close();  
  151.   
  152.     //————————-复制文件到相应目录————————//  
  153.     newpath+=info.fileName();  
  154.     file.copy(newpath);  
  155.     file.close();  
  156.   
  157.   
  158.   
  159.     QFile checkpath(newpath);  
  160.     if(checkpath.open(QFile::ReadOnly))  
  161.     {  
  162.         QMessageBox msgBox;  
  163.         msgBox.setText(”文件复制成功”);  
  164.         msgBox.setStandardButtons(QMessageBox::Ok);  
  165.         msgBox.exec();  
  166.     }  
  167.     checkpath.close();  
  168.   
  169.   
  170.   
  171.   
  172. }  
  173.   
  174. void UpLoadFrame::doBookFaceClicked()  
  175. {  
  176.     picpath=QFileDialog::getOpenFileName(this,“指定封面”);  
  177.     bookface->setIcon(QIcon(picpath));  
  178. }  
#include "uploadframe.h"

include<QLabel>

include<QIcon>

include<QLineEdit>

include<QPushButton>

include<QTextBrowser>

include<QToolButton>

include<QHBoxLayout>

include<QVBoxLayout>

include<QFile>

include<QFIleDialog>

include<QFileInfo>

include<QMessageBox>

include<QDir>

include<QTextStream>

UpLoadFrame::UpLoadFrame(QWidget *parent) : QWidget(parent)
{

filepath=new QLineEdit(this);
choosepath=new QPushButton(this);
bookface=new QToolButton();
writername=new QLineEdit(this);
publisher=new QLineEdit(this);
bookname=new QLineEdit(this);
aboutbook=new QLineEdit(this);
init();
connect(choosepath,SIGNAL(clicked(bool)),this,SLOT(doChoosepathbutton()));
connect(saveButton,SIGNAL(clicked(bool)),this,SLOT(doSaveButton()));
connect(bookface,SIGNAL(clicked(bool)),this,SLOT(doBookFaceClicked()));
setFixedSize(400,300);

}

void UpLoadFrame::init()
{
QVBoxLayout *mainLayout=new QVBoxLayout(this);
QHBoxLayout *hLayout_one=new QHBoxLayout(this);

filepath-&gt;setMinimumSize(250,20);
filepath-&gt;setMaximumSize(250,20);
filepath-&gt;setContentsMargins(0,0,0,0);
choosepath-&gt;setText("选择文件");
choosepath-&gt;setMaximumHeight(30);
choosepath-&gt;setMinimumHeight(30);
choosepath-&gt;setContentsMargins(0,0,0,0);hLayout_one-&gt;addWidget(filepath);
hLayout_one-&gt;addStretch();
hLayout_one-&gt;addWidget(choosepath);
hLayout_one-&gt;setContentsMargins(0,0,0,0);QHBoxLayout *hLayout_two=new QHBoxLayout(this);bookface-&gt;setIconSize(QSize(150,150));QVBoxLayout *vLayout_bookinfo=new QVBoxLayout(this);QHBoxLayout *hLayout_two_one=new QHBoxLayout(this);
QLabel *static_writer=new QLabel("作者",this);
writername-&gt;setFixedSize(100,30);
hLayout_two_one-&gt;addWidget(static_writer);
hLayout_two_one-&gt;addStretch();
hLayout_two_one-&gt;addWidget(writername);QHBoxLayout *hLayout_two_two=new QHBoxLayout(this);
QLabel *static_bookname=new QLabel("书名",this);
bookname-&gt;setFixedSize(100,30);
hLayout_two_two-&gt;addWidget(static_bookname);
hLayout_two_two-&gt;addStretch();
hLayout_two_two-&gt;addWidget(bookname);QHBoxLayout *hLayout_two_three=new QHBoxLayout(this);
QLabel *static_publisher=new QLabel("出版社",this);
publisher-&gt;setFixedSize(100,30);
hLayout_two_three-&gt;addWidget(static_publisher);
hLayout_two_three-&gt;addStretch();
hLayout_two_three-&gt;addWidget(publisher);vLayout_bookinfo-&gt;addLayout(hLayout_two_one);
vLayout_bookinfo-&gt;addLayout(hLayout_two_two);
vLayout_bookinfo-&gt;addLayout(hLayout_two_three);hLayout_two-&gt;addWidget(bookface);
hLayout_two-&gt;addStretch();
hLayout_two-&gt;addLayout(vLayout_bookinfo);aboutbook =new QLineEdit(this);
saveButton=new QPushButton(this);
saveButton-&gt;setText("保存文件");
saveButton-&gt;setMinimumWidth(this-&gt;width()*0.8);
mainLayout-&gt;addLayout(hLayout_one);
mainLayout-&gt;addStretch();
mainLayout-&gt;addLayout(hLayout_two);
mainLayout-&gt;addWidget(saveButton);
mainLayout-&gt;addWidget(aboutbook);
setLayout(mainLayout);

}

void UpLoadFrame::doChoosepathbutton()
{
fileName =QFileDialog::getOpenFileName(this,tr(“打开文件”));
filepath->setText(fileName);
QFileInfo info(fileName);
bookname->setText(info.baseName());
}

void UpLoadFrame::doSaveButton()
{
QFile file(fileName);
QFileInfo info(fileName);
QString newpath=QString(“G:/Reader_Resource”)+QString(“/”);

//————————创建对应书籍的目录————————//
QDir dir;
dir.cd(newpath);
dir.mkdir(info.baseName());
newpath+=info.baseName();
//—————-读取图书的信息并保存在对应的目录下—————–//

QFile bookinfo(newpath+"/"+info.baseName()+".txt");
QFileInfo tmp(bookinfo);
aboutbook-&gt;setText(tmp.absoluteFilePath());
if( bookinfo.open(QFile::ReadWrite))
{QTextStream out(&amp;bookinfo);out&lt;&lt;writername-&gt;text()&lt;&lt;"\r\n"&lt;&lt;endl;out&lt;&lt;bookname-&gt;text()&lt;&lt;"\r\n"&lt;&lt;endl;out&lt;&lt;publisher-&gt;text()&lt;&lt;"\r\n"&lt;&lt;endl;
}bookinfo.setFileName(info.baseName()+".txt");
bookinfo.close();
//--------------------------------------------------------------//newpath+=QString("/");//----------------------复制图片封面信息------------------------//
QFile picfile(picpath);
QFileInfo picinfo(picfile);
QString temptopicpath=newpath;
temptopicpath+=picinfo.fileName();
picfile.copy(temptopicpath);
picfile.close();//-------------------------复制文件到相应目录------------------------//
newpath+=info.fileName();
file.copy(newpath);
file.close();QFile checkpath(newpath);
if(checkpath.open(QFile::ReadOnly))
{QMessageBox msgBox;msgBox.setText("文件复制成功");msgBox.setStandardButtons(QMessageBox::Ok);msgBox.exec();
}
checkpath.close();

}

void UpLoadFrame::doBookFaceClicked()
{
picpath=QFileDialog::getOpenFileName(this,”指定封面”);
bookface->setIcon(QIcon(picpath));
}

        </div>

这篇关于Qt 文件的操作以及实现的文件的复制操作并且在相应的目的地创建文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/792701

相关文章

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

嵌入式QT开发:构建高效智能的嵌入式系统

摘要: 本文深入探讨了嵌入式 QT 相关的各个方面。从 QT 框架的基础架构和核心概念出发,详细阐述了其在嵌入式环境中的优势与特点。文中分析了嵌入式 QT 的开发环境搭建过程,包括交叉编译工具链的配置等关键步骤。进一步探讨了嵌入式 QT 的界面设计与开发,涵盖了从基本控件的使用到复杂界面布局的构建。同时也深入研究了信号与槽机制在嵌入式系统中的应用,以及嵌入式 QT 与硬件设备的交互,包括输入输出设

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

在cscode中通过maven创建java项目

在cscode中创建java项目 可以通过博客完成maven的导入 建立maven项目 使用快捷键 Ctrl + Shift + P 建立一个 Maven 项目 1 Ctrl + Shift + P 打开输入框2 输入 "> java create"3 选择 maven4 选择 No Archetype5 输入 域名6 输入项目名称7 建立一个文件目录存放项目,文件名一般为项目名8 确定

Kubernetes PodSecurityPolicy:PSP能实现的5种主要安全策略

Kubernetes PodSecurityPolicy:PSP能实现的5种主要安全策略 1. 特权模式限制2. 宿主机资源隔离3. 用户和组管理4. 权限提升控制5. SELinux配置 💖The Begin💖点点关注,收藏不迷路💖 Kubernetes的PodSecurityPolicy(PSP)是一个关键的安全特性,它在Pod创建之前实施安全策略,确保P