本文整理汇总了C++中QString::capacity方法的典型用法代码示例。如果您正苦于以下问题:C++ QString::capacity方法的具体用法?C++ QString::capacity怎么用?C++ QString::capacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QString
的用法示例。
在下文中一共展示了QString::capacity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnSave
void WdgAddStation::OnSave()
{
QString Str = ui.leComment->text();
if(Str.capacity()<1)
return;
if(ui.sbFreq->value() > 100000 && ui.sbFreq->value() < 440000000)
{
emit Station(ui.leComment->text(), ui.sbFreq->value(), ui.comboBox->currentIndex());
close();
}
}
示例2: escapeBLOB
QString KexiDB::escapeBLOB(const QByteArray& array, BLOBEscapingType type)
{
const int size = array.size();
if (size == 0)
return QString();
int escaped_length = size * 2;
if (type == BLOBEscape0xHex || type == BLOBEscapeOctal)
escaped_length += 2/*0x or X'*/;
else if (type == BLOBEscapeXHex)
escaped_length += 3; //X' + '
QString str;
str.reserve(escaped_length);
if (str.capacity() < escaped_length) {
KexiDBWarn << "KexiDB::Driver::escapeBLOB(): no enough memory (cannot allocate " <<
escaped_length << " chars)";
return QString();
}
if (type == BLOBEscapeXHex)
str = QString::fromLatin1("X'");
else if (type == BLOBEscape0xHex)
str = QString::fromLatin1("0x");
else if (type == BLOBEscapeOctal)
str = QString::fromLatin1("'");
int new_length = str.length(); //after X' or 0x, etc.
if (type == BLOBEscapeOctal) {
// only escape nonprintable characters as in Table 8-7:
// http://www.postgresql.org/docs/8.1/interactive/datatype-binary.html
// i.e. escape for bytes: < 32, >= 127, 39 ('), 92(\).
for (int i = 0; i < size; i++) {
const unsigned char val = array[i];
if (val < 32 || val >= 127 || val == 39 || val == 92) {
str[new_length++] = '\\';
str[new_length++] = '\\';
str[new_length++] = '0' + val / 64;
str[new_length++] = '0' + (val % 64) / 8;
str[new_length++] = '0' + val % 8;
} else {
str[new_length++] = val;
}
}
} else {
for (int i = 0; i < size; i++) {
const unsigned char val = array[i];
str[new_length++] = (val / 16) < 10 ? ('0' + (val / 16)) : ('A' + (val / 16) - 10);
str[new_length++] = (val % 16) < 10 ? ('0' + (val % 16)) : ('A' + (val % 16) - 10);
}
}
if (type == BLOBEscapeXHex || type == BLOBEscapeOctal)
str[new_length++] = '\'';
return str;
}
示例3: printer
void MainWindow::on_pushButton_4_clicked()
{
QTextDocument doc;
QString txt;
txt = ::textAt(h3,65,"ASAP Film Order") %
::textAt(h3,40,"From C&C Special Products Co. 952-881-0073") %
::textAt(h3,67,"Mark Robin") %
::textAt(h3,6,"Attn: Customer Service") % ::nbsp(63) % "Rip Settings:"%
::textAt(h3,103,"1) Film Positives") %
::textAt(h3,103,"2) DO NOT TRAP") %
::textAt(h3,103,"3) Send Pre Separated") %
::textAt(h3,6,"Date: " % ui->dateEdit->text()) %
::textAt(h3,6,"File Name: " % ui->lineEdit_2->text());
qDebug() << "The memory used is: " << txt.capacity();
doc.setHtml(txt);
#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG)
QPrinter printer(QPrinter::HighResolution);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
dlg->setWindowTitle(tr("Print Document"));
if (dlg->exec() == QDialog::Accepted)
{
QPrinter printer;
// printer.setOutputFileName("c:\\temp\\filenew.pdf");
// printer.setOutputFormat(QPrinter::PdfFormat);
qDebug() << "Sending to printer";
doc.print(&printer);
printer.newPage();
printer.setOutputFileName("c:\\temp\\faxASAP.pdf");
printer.setOutputFormat(QPrinter::PdfFormat);
qDebug() << "Creating PDF";
doc.print(&printer);
printer.newPage();
}
delete dlg;
#endif
}
示例4: read
bool QMakeParser::read(ProFile *pro, const QString &in, int line, SubGrammar grammar)
{
m_proFile = pro;
m_lineNo = line;
// Final precompiled token stream buffer
QString tokBuff;
// Worst-case size calculations:
// - line marker adds 1 (2-nl) to 1st token of each line
// - empty assignment "A=":2 =>
// TokHashLiteral(1) + hash(2) + len(1) + "A"(1) + TokAssign(1) + 0(1) +
// TokValueTerminator(1) == 8 (9)
// - non-empty assignment "A=B C":5 =>
// TokHashLiteral(1) + hash(2) + len(1) + "A"(1) + TokAssign(1) + 2(1) +
// TokLiteral(1) + len(1) + "B"(1) +
// TokLiteral(1) + len(1) + "C"(1) + TokValueTerminator(1) == 14 (15)
// - variable expansion: "$$f":3 =>
// TokVariable(1) + hash(2) + len(1) + "f"(1) = 5
// - function expansion: "$$f()":5 =>
// TokFuncName(1) + hash(2) + len(1) + "f"(1) + TokFuncTerminator(1) = 6
// - scope: "X:":2 =>
// TokHashLiteral(1) + hash(2) + len(1) + "A"(1) + TokCondition(1) +
// TokBranch(1) + len(2) + ... + len(2) + ... == 10
// - test: "X():":4 =>
// TokHashLiteral(1) + hash(2) + len(1) + "A"(1) + TokTestCall(1) + TokFuncTerminator(1) +
// TokBranch(1) + len(2) + ... + len(2) + ... == 11
// - "for(A,B):":9 =>
// TokForLoop(1) + hash(2) + len(1) + "A"(1) +
// len(2) + TokLiteral(1) + len(1) + "B"(1) + TokValueTerminator(1) +
// len(2) + ... + TokTerminator(1) == 14 (15)
tokBuff.reserve((in.size() + 1) * 5);
ushort *tokPtr = (ushort *)tokBuff.constData(); // Current writing position
// Expression precompiler buffer.
QString xprBuff;
xprBuff.reserve(tokBuff.capacity()); // Excessive, but simple
ushort *buf = (ushort *)xprBuff.constData();
// Parser state
m_blockstack.clear();
m_blockstack.resize(1);
QStack<ParseCtx> xprStack;
xprStack.reserve(10);
// We rely on QStrings being null-terminated, so don't maintain a global end pointer.
const ushort *cur = (const ushort *)in.unicode();
m_canElse = false;
freshLine:
m_state = StNew;
m_invert = false;
m_operator = NoOperator;
m_markLine = m_lineNo;
m_inError = false;
int parens = 0; // Braces in value context
int argc = 0;
int wordCount = 0; // Number of words in currently accumulated expression
int lastIndent = 0; // Previous line's indentation, to detect accidental continuation abuse
bool lineMarked = true; // For in-expression markers
ushort needSep = TokNewStr; // Met unquoted whitespace
ushort quote = 0;
ushort term = 0;
Context context;
ushort *ptr;
if (grammar == ValueGrammar) {
context = CtxPureValue;
ptr = tokPtr + 2;
} else {
context = CtxTest;
ptr = buf + 4;
}
ushort *xprPtr = ptr;
#define FLUSH_LHS_LITERAL() \
do { \
if ((tlen = ptr - xprPtr)) { \
finalizeHashStr(xprPtr, tlen); \
if (needSep) { \
wordCount++; \
needSep = 0; \
} \
} else { \
ptr -= 4; \
} \
} while (0)
#define FLUSH_RHS_LITERAL() \
do { \
if ((tlen = ptr - xprPtr)) { \
xprPtr[-2] = TokLiteral | needSep; \
xprPtr[-1] = tlen; \
if (needSep) { \
wordCount++; \
needSep = 0; \
} \
} else { \
ptr -= 2; \
} \
} while (0)
//.........这里部分代码省略.........
示例5: exportData
bool KexiCSVExport::exportData(KDbTableOrQuerySchema *tableOrQuery,
const Options& options, int recordCount, QTextStream *predefinedTextStream)
{
KDbConnection* conn = tableOrQuery->connection();
if (!conn)
return false;
KDbQuerySchema* query = tableOrQuery->query();
QList<QVariant> queryParams;
if (!query) {
query = tableOrQuery->table()->query();
}
else {
queryParams = KexiMainWindowIface::global()->currentParametersForQuery(query->id());
}
if (recordCount == -1)
recordCount = KDb::recordCount(tableOrQuery, queryParams);
if (recordCount == -1)
return false;
//! @todo move this to non-GUI location so it can be also used via command line
//! @todo add a "finish" page with a progressbar.
//! @todo look at recordCount whether the data is really large;
//! if so: avoid copying to clipboard (or ask user) because of system memory
//! @todo OPTIMIZATION: use fieldsExpanded(true /*UNIQUE*/)
//! @todo OPTIMIZATION? (avoid multiple data retrieving) look for already fetched data within KexiProject..
KDbQueryColumnInfo::Vector fields(query->fieldsExpanded(KDbQuerySchema::WithInternalFields));
QString buffer;
QScopedPointer<QSaveFile> kSaveFile;
QTextStream *stream = 0;
QScopedPointer<QTextStream> kSaveFileTextStream;
const bool copyToClipboard = options.mode == Clipboard;
if (copyToClipboard) {
//! @todo (during exporting): enlarge bufSize by factor of 2 when it became too small
int bufSize = qMin((recordCount < 0 ? 10 : recordCount) * fields.count() * 20, 128000);
buffer.reserve(bufSize);
if (buffer.capacity() < bufSize) {
qWarning() << "Cannot allocate memory for " << bufSize
<< " characters";
return false;
}
} else {
if (predefinedTextStream) {
stream = predefinedTextStream;
} else {
if (options.fileName.isEmpty()) {//sanity
qWarning() << "Fname is empty";
return false;
}
kSaveFile.reset(new QSaveFile(options.fileName));
qDebug() << "QSaveFile Filename:" << kSaveFile->fileName();
if (kSaveFile->open(QIODevice::WriteOnly)) {
kSaveFileTextStream.reset(new QTextStream(kSaveFile.data()));
stream = kSaveFileTextStream.data();
qDebug() << "have a stream";
}
if (QFileDevice::NoError != kSaveFile->error() || !stream) {//sanity
qWarning() << "Status != 0 or stream == 0";
//! @todo show error
return false;
}
}
}
//! @todo escape strings
#define _ERR \
if (kSaveFile) { kSaveFile->cancelWriting(); } \
return false
#define APPEND(what) \
if (copyToClipboard) buffer.append(what); else (*stream) << (what)
// use native line ending for copying, RFC 4180 one for saving to file
#define APPEND_EOLN \
if (copyToClipboard) { APPEND('\n'); } else { APPEND("\r\n"); }
qDebug() << 0 << "Columns: " << query->fieldsExpanded().count();
// 0. Cache information
const int fieldsCount = query->fieldsExpanded().count(); //real fields count without internals
const QByteArray delimiter(options.delimiter.left(1).toLatin1());
const bool hasTextQuote = !options.textQuote.isEmpty();
const QString textQuote(options.textQuote.left(1));
const QByteArray escapedTextQuote((textQuote + textQuote).toLatin1()); //ok?
//cache for faster checks
QScopedArrayPointer<bool> isText(new bool[fieldsCount]);
QScopedArrayPointer<bool> isDateTime(new bool[fieldsCount]);
QScopedArrayPointer<bool> isTime(new bool[fieldsCount]);
QScopedArrayPointer<bool> isBLOB(new bool[fieldsCount]);
QScopedArrayPointer<int> visibleFieldIndex(new int[fieldsCount]);
// bool isInteger[fieldsCount]; //cache for faster checks
// bool isFloatingPoint[fieldsCount]; //cache for faster checks
for (int i = 0; i < fieldsCount; i++) {
//.........这里部分代码省略.........