本文整理汇总了C++中QTextStream::setString方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextStream::setString方法的具体用法?C++ QTextStream::setString怎么用?C++ QTextStream::setString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextStream
的用法示例。
在下文中一共展示了QTextStream::setString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportToDBMS
//.........这里部分代码省略.........
}
catch(Exception &e)
{
/* Raises an error if the object is duplicated and the ignore duplicity is not set or the error
returned by the server is other than object duplicity */
if(!ignore_dup ||
(ignore_dup &&
std::find(err_codes_vect.begin(), err_codes_vect.end(), e.getExtraInfo())==err_codes_vect.end()))
throw Exception(e.getErrorMessage(),
e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e, sql_cmd);
else
errors.push_back(e);
}
if(!export_canceled)
{
//Connects to the new created database to create the other objects
progress=20;
new_db_conn=conn;
new_db_conn.setConnectionParam(Connection::PARAM_DB_NAME, db_model->getName());
emit s_progressUpdated(progress,
trUtf8("Connecting to database `%1'...").arg(Utf8String::create(db_model->getName())));
new_db_conn.connect();
progress=30;
//Creating the other object types
emit s_progressUpdated(progress, trUtf8("Creating objects on database `%1'...").arg(Utf8String::create(db_model->getName())));
//Generates the sql from entire model
sql_buf=db_model->getCodeDefinition(SchemaParser::SQL_DEFINITION, false);
/* Extract each SQL command from the buffer and execute them separately. This is done
to permit the user, in case of error, identify what object is wrongly configured. */
ts.setString(&sql_buf);
unsigned aux_prog=0, curr_size=0, buf_size=sql_buf.size();
progress+=(sql_gen_progress/progress);
sql_cmd.clear();
while(!ts.atEnd() && !export_canceled)
{
try
{
//Cleanup single line comments
lin=ts.readLine();
curr_size+=lin.size();
aux_prog=progress + ((curr_size/static_cast<float>(buf_size)) * 70);
ddl_tk_found=(lin.indexOf(ParsersAttributes::DDL_END_TOKEN) >= 0);
lin.remove(QRegExp("^(--)+(.)+$"));
//If the line isn't empty after cleanup it will be included on sql command
if(!lin.isEmpty())
sql_cmd += lin + "\n";
//If the ddl end token is found
if(ddl_tk_found || (!sql_cmd.isEmpty() && ts.atEnd()))
{
//Regexp used to extract the object being created
QRegExp reg=QRegExp("(CREATE)(.)+(\n)", Qt::CaseSensitive);
sql_cmd.simplified();
//Check if the regex matches the sql command
if(reg.exactMatch(sql_cmd))
{
示例2: createXMLFileFromQuery
QString SafetVariable::createXMLFileFromQuery(const QSqlQuery& query, const QString& outputFileName ) const {
QString result;
Q_ASSERT_X(!outputFileName.isEmpty(),
"SafetDocument::createXMLFileFromSQL()",
qPrintable(QObject::tr("outputFileName vacio")));
if (outputFileName.isEmpty()){
qDebug("cadena outputFileName vacia");
return result;
}
QFile file;
bool open;
QTextStream out;
bool istext = outputFileName.compare("::text", Qt::CaseInsensitive) == 0;
if ( !istext ) {
file.setFileName(outputFileName);
open = file.open(QIODevice::WriteOnly | QIODevice::Text);
Q_ASSERT_X(open,
"SafetDocument::createXMLFileFromSQL()",
qPrintable(QObject::tr("No se pudo crear el archivo XML correspondiente a la sentencia SQL.")));
out.setDevice(&file);
}
else {
out.setString(&result);
}
QSqlRecord rec;
rec = query.record();
out << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" << "\n";
out << "<libsafetdb>" << "\n";
QString cadena("");
//qDebug("<: %s", qPrintable(x.setNum(j+1)), ">");
// qDebug("\t<Document>");
out << "<Document>" << "\n" ;
for (int i= 0; i< rec.count(); i++){
//qDebug(qPrintable(rec.fieldName(i)));
//qDebug(qPrintable(query.value(i).toString()));
cadena.append("<");
cadena.append(rec.fieldName(i));
cadena.append(">");
cadena.append(query.value(i).toString());
cadena.append("</");
cadena.append(rec.fieldName(i));
cadena.append(">");
// qDebug(qPrintable(cadena));
out << cadena << "\n" ;
cadena.clear();
}
// qDebug("</Document>");
out << "</Document>" << "\n" << "</libsafetdb>" << "\n";
return result;
}