本文整理汇总了C++中QTextStream类的典型用法代码示例。如果您正苦于以下问题:C++ QTextStream类的具体用法?C++ QTextStream怎么用?C++ QTextStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: facultiesCsv
bool CSVOldFormatConverter::convertFaculties(QString csvDirPath) {
QFile facultiesCsv(csvDirPath + "/Факультет.csv");
QTextStream facultiesStream;
facultiesStream.setDevice(&facultiesCsv);
facultiesStream.setCodec("UTF-8");
if (!facultiesCsv.open(QIODevice::ReadOnly)) {
return false;
}
QSqlQuery query;
query.prepare("INSERT INTO university_faculty (name) VALUES (?)");
while (!facultiesStream.atEnd()) {
query.addBindValue(facultiesStream.readLine().split(';').at(1));
if (!query.exec()) {
return false;
}
}
return true;
}
示例2: loadDatData
/*!
\brief Load .dat file
\param in QTextStream which holds the .dat file
SEGNAME, TYPE, FROM, TO and LENGTH are loaded from the file
// TODO(panqing): Error processing should be added
*/
int DataIO::loadDatData(QTextStream &in)
{
QString line; // One line of the file
QStringList lineList; // Items in one line, seperated by some delimiters
const int lengthThreshold = 10; // Recognize one line as a recording by its length
while (!(line = in.readLine()).contains("SEGMENT"))
;
// 数据列之间可用tab或space分隔
if(line.contains("\t"))
lineList = line.split("\t", QString::SkipEmptyParts);
else
lineList = line.split(" ", QString::SkipEmptyParts);
// FROM and TO are inserted into the attributes name list
// NOTICE(panqing): because the SEGMENT NAME takes 2 positions in the lineList,
// the indices of FROM and TO (3, 4) are different from those below (2, 3)
attributesMap.insert(false, lineList.at(3));
attributesMap.insert(false, lineList.at(4));
// LENGTH are inserted into the show name list
attributesMap.insert(true, lineList.at(6));
while ((line = in.readLine()).length() >= lengthThreshold)
{
EdgeAttr *edgeAttr = new EdgeAttr();
// There are two format of the separator: tab and space
if(line.contains("\t"))
lineList = line.split("\t", QString::SkipEmptyParts);
else
lineList = line.split(" ", QString::SkipEmptyParts);
edgeAttr->setIntAttr(EdgeAttr::SEGNAME, lineList.at(0).toInt());
edgeAttr->setIntAttr(EdgeAttr::TYPE, lineList.at(1).toInt()); // NOTICE(panqing): Type in *.dat and *.prn are DIFFERENT!!!!!! Use the type from .dat file
edgeAttr->setIntAttr(EdgeAttr::STARTNODE, lineList.at(2).toInt());
edgeAttr->setIntAttr(EdgeAttr::ENDNODE, lineList.at(3).toInt());
edgeAttr->setDoubleAttr(EdgeAttr::OLDDIAM, lineList.at(4).toDouble());
edgeAttr->setDoubleAttr(EdgeAttr::LENGTH, lineList.at(5).toDouble());
edgeAttrList.append(edgeAttr); // ResManager::getEdgeAttrList() returns a reference to DataList
}
return 0;
}
示例3: CloseHeader
void
CloseHeader(QTextStream &file, const QString &pre_name_withoutpath)
{
// close the file
file.device()->close();
delete file.device();
QString pre_name;
if (outputtoinputdir)
pre_name = currentInputDir + pre_name_withoutpath;
else
pre_name = pre_name_withoutpath;
// create the real target file name
QString post_name = pre_name.right(pre_name.length() - preHeaderLeader.length());
unsigned int pre_cksum;
FileContentsChecksum(pre_name, &pre_cksum);
unsigned int post_cksum;
bool havePostFile = FileContentsChecksum(post_name, &post_cksum);
if (havePostFile)
{
if (post_cksum == pre_cksum)
{
// Since the new header file is the same as the old, don't
// touch the old and remove the new (pre) one.
QFile(pre_name).remove();
cOut << "Note: Header file \"" << post_name << "\" did NOT change." << Endl;
}
else
{
// Since the new headeer file is different from the old,
// remove the old one and rename the new one.
QFile(post_name).remove();
QFile(pre_name).rename(post_name);
cOut << "Note: Header file \"" << post_name << "\" changed." << Endl;
}
}
else
{
QFile(pre_name).rename(post_name);
}
}
示例4: defined
/**
* @brief Constructs binary command line.
* @param parfile Parameter file.
* @param num_iter Number of iterations.
* @param step_size Step size.
* @return 0 if success, else -1.
*/
int BinaryHandler::_set_bin_settings(const QString& parfile, const int num_iter,
const int step_size)
{
QString fname = "progress_" + QString::number(_id) + ".txt";
if (_output_style == "Humppa") {
fname = QString::number(_id) + "______progressbar.txt";
}
_progress_file.setFileName(fname);
QString path_style = "..\bin\\";
#if defined(__linux__) || defined(__APPLE__)
path_style = "../bin/";
#endif
_cmd = "";
QTextStream str;
str.setString(&_cmd);
// Check if we're dealing with a Python script.
// It is users responsibility to make sure Python is available!
QStringList blist = _binary.split(".");
if (blist.size() > 1 && blist.at(1) == "py") {
str << "python ";
}
str << path_style << _binary << " ";
if (_input_style == "MorphoMaker" || _input_style == "") {
str << "--param " << parfile << " --id " << _id << " --step "
<< step_size << " --niter " << num_iter;
}
else if (_input_style == "Humppa") {
str << parfile << " " << _id << " " << step_size << " "
<< num_iter/step_size;
}
else {
fprintf(stderr, "Invalid argument style: %s\n",
_input_style.toStdString().c_str());
return -1;
}
if (DEBUG_MODE) fprintf(stderr, "cmd: %s\n", _cmd.toStdString().c_str());
return 0;
}
示例5: parse
DataList ExternalCharges::parse(QTextStream& textStream)
{
bool parseOkay(true), isDouble;
QString line;
QStringList tokens;
double x, y, z, q;
Layer::Data* charges = new Layer::Data("Charges");
while (!textStream.atEnd() && parseOkay) {
line = textStream.readLine();
if (line.contains("$external_charges", Qt::CaseInsensitive)) {
}else if (line.contains("$end", Qt::CaseInsensitive)) {
break;
}else {
tokens = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
if (tokens.count() == 1) {
tokens[0].toUInt(&parseOkay);
}else if (tokens.count() == 4) {
x = tokens[0].toDouble(&isDouble); parseOkay = parseOkay && isDouble;
y = tokens[1].toDouble(&isDouble); parseOkay = parseOkay && isDouble;
z = tokens[2].toDouble(&isDouble); parseOkay = parseOkay && isDouble;
q = tokens[3].toDouble(&isDouble); parseOkay = parseOkay && isDouble;
if (parseOkay) charges->appendRow(new Layer::Charge(q, qglviewer::Vec(x,y,z)));
}else {
parseOkay = false;
}
}
}
if (parseOkay && charges->hasChildren()) {
m_dataList.append(charges);
}else {
ChargeList list(charges->findLayers<Layer::Charge>(Layer::Children));
ChargeList::iterator charge;
for (charge = list.begin(); charge != list.end(); ++charge) {
delete (*charge);
}
delete charges;
}
return m_dataList;
}
示例6: LogInit
namespace nuts {
QTextStream err;
QTextStream log;
class CLogInit {
public:
CLogInit() {
int fd1 = dup(1), fd2 = dup(2);
close(fd1); close(fd2);
if (fd1 == -1 || fd2 == -1) {
QFile *f = new QFile("/var/log/nuts.log");
f->open(QIODevice::Append);
dup2(f->handle(), 2);
dup2(f->handle(), 1);
err.setDevice(f);
log.setDevice(f);
} else {
ferr = new QFile(); ferr->open(2, QIODevice::WriteOnly);
err.setDevice(ferr);
fout = new QFile(); fout->open(1, QIODevice::WriteOnly);
log.setDevice(fout);
}
}
~CLogInit() {
delete ferr;
delete fout;
}
private:
QFile *ferr = nullptr;
QFile *fout = nullptr;
};
static CLogInit *loginit;
void LogInit() {
loginit = new CLogInit();
}
void LogDestroy() {
delete loginit;
loginit = nullptr;
}
}
示例7: while
QList<QStringList> CsvReader::parseTextStream(QTextStream& in)
{
QList<QStringList> parsedFile;
bool firstLine = true;
while (!in.atEnd()) {
QString line = in.readLine();
if (firstLine && hasHeader_) {
firstLine = false;
continue;
}
QStringList parsedList = line.split(delimiter_);
parsedFile.append(parsedList);
}
return parsedFile;
}
示例8: readHexagons
void GameEngine::readHexagons(QTextStream &input)
{
QString buf;
buf = input.readLine();
while ((buf != "[/HEXAGONS]") && (buf.size() != 0))
{
QStringList list = buf.split(" ", QString::SkipEmptyParts);
int curHexagon = list[0].toInt() - 1;
for (int i = 1; i < list.size(); ++i)
{
hexagons[curHexagon].setVertex(vertexes[list[i].toInt()-1]);
}
list.clear();
buf = input.readLine();
list = buf.split(" ");
hexagons[curHexagon].setNominalCoord(list[0].toInt(), list[1].toInt());
buf = input.readLine();
}
}
示例9: mFile
void Dialog::on_comboBox_activated(const QString &arg1)
{
str = ui->comboBox->currentText();
QFile mFile(str);
if(!mFile.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox msgBox;
msgBox.setText("Error.");
msgBox.exec();
return;
}
QTextStream stream (&mFile);
str=stream.readAll();
ui->label_2->setText(str);
}
示例10: isError
/**
Take a stream onto a control file and return the decoded
package information.
Set isError == true if the information format is wrong.
*/
PackageInformationReader::PackageInformationReader( QTextStream &ts,
InstallControl::PackageInfo::Source src )
: isError( false )
, hasContent( false )
, wasSizeUpdated( false )
, accumulatingFullDesc( false )
, source( src )
{
reset();
while (!ts.atEnd())
{
QString line = ts.readLine();
readLine( line );
}
updateInstalledSize();
if ( !pkg.isComplete(source, &error) )
isError = true;
}
示例11: file
QString vars::get_tool(QString toolname)
{
QString tool = "";
QFile file ( QDir::homePath() +"/.first4/"+username+".first4.conf" );
if ( file.open ( QIODevice::ReadOnly ) )
{
QTextStream stream ( &file );
QString streamline;
while(!stream.atEnd())
{
streamline = stream.readLine();
if(streamline.contains(toolname+"=", Qt::CaseSensitive))
tool = streamline.section("=", 1, 1);
}
file.close();
}
if(tool == "")
{
QString os = "";
#ifdef Q_OS_LINUX
os="lnx";
#endif
#ifdef Q_OS_WIN32
os="win";
#endif
#ifdef Q_OS_MAC
os="mac";
#endif
QString qstr1 = QString("SELECT var, value FROM maincfg WHERE `var`='tool_%1_"+toolname.toLower()+"';").arg(os);
QSqlQuery querytools(qstr1);
if ( querytools.isActive())
{
querytools.next();
tool = querytools.value(1).toString();
}
else
{
QSqlError sqlerror = querytools.lastError();
QMessageBox::critical(0,"Error...", "Unable to read settings from database!\n\n"+sqlerror.text());
}
}
return tool;
}
示例12: readStars
void readStars(QTextStream &stream, Galaxy &galaxy)
{
QString line = stream.readLine().trimmed();
while (!line.isNull())
{
if(line.contains("StarId"))
{
QStringRef idRef(&line,6,line.indexOf(' ')-6);
unsigned id=idRef.toInt();
galaxy.addStar(Star(stream, galaxy, id));
}
else if(line.contains('}'))
{
break;
}
line = stream.readLine().trimmed();
}
}
示例13: qMax
void QWSHexDump::sideviewDump(int at)
{
if (dirty) {
dirty = false;
++at;
sideview[at] = '\0';
int currentWidth = (2 * at) + (at / clustering) - (at%clustering?0:1);
int missing = qMax(dataWidth - currentWidth, 0);
while (missing--)
*outstrm << ' ';
*outstrm << " [";
outstrm->setPadChar(' ');
outstrm->setFieldWidth(wrap);
outstrm->setFieldAlignment( QTextStream::AlignLeft );
*outstrm << sideview;
*outstrm << ']';
}
}
示例14: QDialog
ReportGenerationDialog::ReportGenerationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ReportGenerationDialog),patientTracker(NULL)
{
ui->setupUi(this);
ui->presetDiagnosisComboBox->setEnabled(true);
ui->diagnosisEditor->setEnabled(false);
ui->screenshotListView->setModel(&screenshotModel);
ui->screenshotListView->setIconSize(QSize(225, 225));
ui->selectedScreenshotListView->setModel(&selectedScreenshotModel);
ui->selectedScreenshotListView->setIconSize(QSize(175, 175));
QScrollArea *area = new QScrollArea(this);
area->move(10, 90);
area->resize(781, 600);
area->setWidget(ui->centreWidget);
ui->tcdInfoTableView->setModel(&selectedValuesModel);
QStringList headerList;
headerList << "截图" << "血管名" << "Mean" << "Peak" << "EDV" << "PI" << "RI" << "S/D" << "HR";
selectedValuesModel.setHorizontalHeaderLabels(headerList);
QFile file("./PresetDiagnoses.txt");
QTextStream in;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox::warning(NULL, "预设诊断读取", "预设诊断读取失败!");
}
else
{
in.setDevice(&file);
QString line;
line = in.readLine();
while (!line.isNull()) {
ui->presetDiagnosisComboBox->addItem(line);
diagnosesModel.appendRow(new QStandardItem(line));
line = in.readLine();
}
}
}
示例15: loadInstructions
void MXPImporter::loadInstructions( QTextStream &stream, Recipe &recipe )
{
//==========================instructions ( along with other optional fields... mxp format doesn't define end of ingredients and start of other fields )==============//
stream.skipWhiteSpace();
QString current = stream.readLine().trimmed();
while ( !current.contains( "- - - -" ) && !stream.atEnd() ) {
if ( current.trimmed() == "Source:" ) {
Element new_author( getNextQuotedString( stream ) );
recipe.authorList.append( new_author );
//kDebug()<<"Found source: "<<new_author.name<<" (adding as author)";
}
else if ( current.trimmed() == "Description:" ) {
QString description = getNextQuotedString( stream );
//kDebug()<<"Found description: "<<m_description<<" (adding to end of instructions)";
recipe.instructions += "\n\nDescription: " + description;
}
else if ( current.trimmed() == "S(Internet Address):" ) {
QString internet = getNextQuotedString( stream );
//kDebug()<<"Found internet address: "<<m_internet<<" (adding to end of instructions)";
recipe.instructions += "\n\nInternet address: " + internet;
}
else if ( current.trimmed() == "Yield:" ) {
recipe.yield.setAmount(getNextQuotedString( stream ).trimmed().toInt());
recipe.yield.setType(i18n("servings"));
//kDebug()<<"Found yield: "<<recipe.yield.amount<<" (adding as servings)";
}
else if ( current.trimmed() == "T(Cook Time):" ) {
( void ) getNextQuotedString( stream ); //this would be prep time, but we don't use prep time at the moment
//kDebug()<<"Found cook time: "<<m_prep_time<<" (adding as prep time)";
}
else if ( current.trimmed() == "Cuisine:" ) {
Element new_cat( getNextQuotedString( stream ) );
recipe.categoryList.append( new_cat );
//kDebug()<<"Found cuisine (adding as category): "<<new_cat.name;
}
else
recipe.instructions += current + '\n';
current = stream.readLine().trimmed();
}
recipe.instructions = recipe.instructions.trimmed();
//kDebug()<<"Found instructions: "<<m_instructions;
}