本文整理汇总了C++中QTemporaryFile::setFileName方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::setFileName方法的具体用法?C++ QTemporaryFile::setFileName怎么用?C++ QTemporaryFile::setFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::setFileName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onButtonSendClicked
void Shoter::onButtonSendClicked()
{
/*Create file */
QDate date = QDate::currentDate();
QString name_file = date.toString();
QString savedFile = name_file+".png";
QTemporaryFile file;
file.setFileName(savedFile);
if (!m_screenshot.save(&file)) {
qDebug("file is not saved");
exit(1);
}
// qDebug()<<file.fileName();
QFile *openFile = new QFile(savedFile);
openFile->open(QIODevice::ReadOnly);
QHttpMultiPart *multi = new QHttpMultiPart(QHttpMultiPart::FormDataType);
/* Upload to ipix.su */
if (ui->comboBox->currentIndex()== 0) {
QHttpPart file;
file.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("image/png"));
file.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data; name=\"file\"; filename=\""+savedFile+"\""));
file.setBodyDevice(openFile);
openFile->setParent(multi);
multi->append(file);
this->upload("http://ipix.su/api/upload",multi);
/* upload to pix.academ.org */
} else if (ui->comboBox->currentIndex() == 1) {
QHttpPart action;
action.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("name=\"action\""));
action.setBody("upload_image");
QHttpPart image;
image.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
image.setHeader(QNetworkRequest::ContentDispositionHeader,
QVariant("form-data; name=\"image\"; filename=\""+savedFile+"\""));
image.setBodyDevice(openFile);
openFile->setParent(multi);
multi->append(action);
multi->append(image);
upload("http://pix.academ.org", multi);
/* Upload to ompldr.org*/
} else if (ui->comboBox->currentIndex() == 2) {
QHttpPart file1;
file1.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
file1.setHeader(QNetworkRequest::ContentDispositionHeader,
QVariant("form-data; name=\"file1\"; filename=\""+savedFile+"\""));
file1.setBodyDevice(openFile);
openFile->setParent(multi);
multi->append(file1);
upload("http://ompldr.org/upload", multi);
}
}
示例2: testProjectFileFilter
void QuickOpenTest::testProjectFileFilter()
{
KTempDir dir;
TestProject* project = new TestProject(KUrl(dir.name()));
ProjectFolderItem* foo = createChild<ProjectFolderItem>(project->projectItem(), "foo");
createChild<ProjectFileItem>(foo, "bar");
createChild<ProjectFileItem>(foo, "asdf");
ProjectFolderItem* asdf = createChild<ProjectFolderItem>(project->projectItem(), "asdf");
createChild<ProjectFileItem>(asdf, "bar");
QTemporaryFile tmpFile;
tmpFile.setFileName(dir.name() + "aaaa");
QVERIFY(tmpFile.open());
ProjectFileItem* aaaa = new ProjectFileItem(project, KUrl(tmpFile.fileName()), project->projectItem());
QCOMPARE(project->fileSet().size(), 4);
ProjectFileDataProvider provider;
QCOMPARE(provider.itemCount(), 0u);
projectController->addProject(project);
const QStringList original = QStringList() << "aaaa" << "asdf/bar" << "foo/asdf" << "foo/bar";
// lazy load
QCOMPARE(provider.itemCount(), 0u);
provider.reset();
QCOMPARE(items(provider), original);
QCOMPARE(provider.itemText(provider.items().first()), aaaa->url().pathOrUrl());
QCOMPARE(provider.data(0)->text(), QString("aaaa"));
// don't show opened file
QVERIFY(core->documentController()->openDocument(KUrl(tmpFile.fileName())));
// lazy load again
QCOMPARE(items(provider), original);
provider.reset();
QCOMPARE(items(provider), QStringList() << "asdf/bar" << "foo/asdf" << "foo/bar");
// prefer files starting with filter
provider.setFilterText("as");
qDebug() << items(provider);
QCOMPARE(items(provider), QStringList() << "foo/asdf" << "asdf/bar");
// clear filter
provider.reset();
QCOMPARE(items(provider), QStringList() << "asdf/bar" << "foo/asdf" << "foo/bar");
// update on document close, lazy load again
core->documentController()->closeAllDocuments();
QCOMPARE(items(provider), QStringList() << "asdf/bar" << "foo/asdf" << "foo/bar");
provider.reset();
QCOMPARE(items(provider), original);
ProjectFileItem* blub = createChild<ProjectFileItem>(project->projectItem(), "blub");
// lazy load
QCOMPARE(provider.itemCount(), 4u);
provider.reset();
QCOMPARE(provider.itemCount(), 5u);
// ensure we don't add stuff multiple times
QMetaObject::invokeMethod(&provider, "fileAddedToSet",
Q_ARG(KDevelop::IProject*, project),
Q_ARG(KDevelop::IndexedString, blub->indexedUrl()));
QCOMPARE(provider.itemCount(), 5u);
provider.reset();
QCOMPARE(provider.itemCount(), 5u);
// lazy load in this implementation
delete blub;
QCOMPARE(provider.itemCount(), 5u);
provider.reset();
QCOMPARE(provider.itemCount(), 4u);
QCOMPARE(items(provider), original);
projectController->closeProject(project);
provider.reset();
QVERIFY(!provider.itemCount());
}