本文整理汇总了C++中QVersitDocument::setType方法的典型用法代码示例。如果您正苦于以下问题:C++ QVersitDocument::setType方法的具体用法?C++ QVersitDocument::setType怎么用?C++ QVersitDocument::setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVersitDocument
的用法示例。
在下文中一共展示了QVersitDocument::setType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportContacts
/*!
* Converts \a contacts into a list of corresponding QVersitDocuments, using the format given by
* \a versitType.
*
* Returns true on success. If any of the contacts could not be exported, false is returned and
* errorMap() will return a list describing the errors that occurred. The successfully exported
* documents will still be available via documents().
*
* \sa documents(), errorMap()
*/
bool QVersitContactExporter::exportContacts(
const QList<QContact>& contacts,
QVersitDocument::VersitType versitType)
{
int contactIndex = 0;
d->mDocuments.clear();
d->mErrors.clear();
bool ok = true;
foreach (const QContact& contact, contacts) {
if (contact.isEmpty()) {
d->mErrors[contactIndex] = EmptyContactError;
ok = false;
continue;
}
QVersitDocument versitDocument;
versitDocument.setType(versitType);
versitDocument.setComponentType(QLatin1String("VCARD"));
d->exportContact(contact, versitDocument);
d->mDocuments.append(versitDocument);
contactIndex++;
}
return ok;
}
示例2: testWritingVersions
void tst_QVersitWriter::testWritingVersions()
{
mWriter->setDevice(mOutputDevice);
mOutputDevice->open(QBuffer::ReadWrite);
QVersitDocument document;
QVersitProperty property;
property.setName(QString(QString::fromLatin1("FN")));
property.setValue(QString::fromLatin1("John"));
document.addProperty(property);
QByteArray vCard30(
"BEGIN:VCARD\r\n"
"VERSION:3.0\r\n"
"FN:John\r\n"
"END:VCARD\r\n");
QByteArray vCard21(
"BEGIN:VCARD\r\n"
"VERSION:2.1\r\n"
"FN:John\r\n"
"END:VCARD\r\n");
// Given no type or componentType, it should be vCard 3.0
QVERIFY(mWriter->startWriting(document));
mWriter->waitForFinished();
QCOMPARE(mOutputDevice->buffer(), vCard30);
// document type should override the guess
document.setType(QVersitDocument::VCard21Type);
mOutputDevice->buffer().clear();
mOutputDevice->seek(0);
QVERIFY(mWriter->startWriting(document));
mWriter->waitForFinished();
QCOMPARE(mOutputDevice->buffer(), vCard21);
// param to startWriting should override document type
mOutputDevice->buffer().clear();
mOutputDevice->seek(0);
QVERIFY(mWriter->startWriting(document, QVersitDocument::VCard30Type));
mWriter->waitForFinished();
QCOMPARE(mOutputDevice->buffer(), vCard30);
}
示例3: exportItems
/*!
* Converts \a items into a QVersitDocument, using the format given by \a versitType.
* Returns true on success. If any of the items could not be exported, false is returned and
* errorMap() will return a list describing the errors that occurred. The successfully exported
* components will still be available via document().
*
* \sa document(), errorMap()
*/
bool QVersitOrganizerExporter::exportItems(
const QList<QOrganizerItem>& items,
QVersitDocument::VersitType versitType)
{
int itemIndex = 0;
d->mErrors.clear();
d->mResult.clear();
d->mResult.setType(versitType);
d->mResult.setComponentType(QLatin1String("VCALENDAR"));
bool ok = true;
QList<QVersitDocument> results;
foreach (const QOrganizerItem& item, items) {
QVersitDocument document;
document.setType(versitType);
QVersitOrganizerExporter::Error error;
if (d->exportItem(item, &document, &error)) {
results.append(document);
} else {
d->mErrors.insert(itemIndex, error);
ok = false;
}
itemIndex++;
}