Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <qt/csvmodelwriter.h>7#include <QAbstractItemModel>8#include <QFile>9#include <QTextStream>11CSVModelWriter::CSVModelWriter(const QString& _filename, QObject* parent)12: QObject(parent),13filename(_filename)14{15}17void CSVModelWriter::setModel(const QAbstractItemModel *_model)18{19this->model = _model;20}22void CSVModelWriter::addColumn(const QString &title, int column, int role)23{24Column col;25col.title = title;26col.column = column;27col.role = role;29columns.append(col);30}32static void writeValue(QTextStream &f, const QString &value)33{34QString escaped = value;35escaped.replace('"', "\"\"");36f << "\"" << escaped << "\"";37}39static void writeSep(QTextStream &f)40{41f << ",";42}44static void writeNewline(QTextStream &f)45{46f << "\n";47}49bool CSVModelWriter::write()50{51QFile file(filename);52if(!file.open(QIODevice::WriteOnly | QIODevice::Text))53return false;54QTextStream out(&file);56int numRows = 0;57if(model)58{59numRows = model->rowCount();60}62// Header row63for(int i=0; i<columns.size(); ++i)64{65if(i!=0)66{67writeSep(out);68}69writeValue(out, columns[i].title);70}71writeNewline(out);73// Data rows74for(int j=0; j<numRows; ++j)75{76for(int i=0; i<columns.size(); ++i)77{78if(i!=0)79{80writeSep(out);81}82QVariant data = model->index(j, columns[i].column).data(columns[i].role);83writeValue(out, data.toString());84}85writeNewline(out);86}88file.close();90return file.error() == QFile::NoError;91}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.