本文整理汇总了C++中FilePtr::write方法的典型用法代码示例。如果您正苦于以下问题:C++ FilePtr::write方法的具体用法?C++ FilePtr::write怎么用?C++ FilePtr::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePtr
的用法示例。
在下文中一共展示了FilePtr::write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleChannelInitialized
void SftpTest::handleChannelInitialized()
{
if (m_state != InitializingChannel) {
std::cerr << "Unexpected state " << m_state << "in function "
<< Q_FUNC_INFO << "." << std::endl;
earlyDisconnectFromHost();
return;
}
std::cout << "Creating " << m_parameters.smallFileCount
<< " files of 1 KB each ..." << std::endl;
qsrand(QDateTime::currentDateTime().toTime_t());
for (int i = 0; i < m_parameters.smallFileCount; ++i) {
const QString fileName
= QLatin1String("sftptestfile") + QString::number(i + 1);
const FilePtr file(new QFile(QDir::tempPath() + QLatin1Char('/')
+ fileName));
bool success = true;
if (!file->open(QIODevice::WriteOnly | QIODevice::Truncate))
success = false;
if (success) {
int content[1024/sizeof(int)];
for (size_t j = 0; j < sizeof content / sizeof content[0]; ++j)
content[j] = qrand();
file->write(reinterpret_cast<char *>(content), sizeof content);
file->close();
}
success = success && file->error() == QFile::NoError;
if (!success) {
std::cerr << "Error creating local file "
<< qPrintable(file->fileName()) << "." << std::endl;
earlyDisconnectFromHost();
return;
}
m_localSmallFiles << file;
}
std::cout << "Files created. Now uploading..." << std::endl;
foreach (const FilePtr &file, m_localSmallFiles) {
const QString localFilePath = file->fileName();
const QString remoteFp
= remoteFilePath(QFileInfo(localFilePath).fileName());
const SftpJobId uploadJob = m_channel->uploadFile(file->fileName(),
remoteFp, SftpOverwriteExisting);
if (uploadJob == SftpInvalidJob) {
std::cerr << "Error uploading local file "
<< qPrintable(localFilePath) << " to remote file "
<< qPrintable(remoteFp) << "." << std::endl;
earlyDisconnectFromHost();
return;
}
m_smallFilesUploadJobs.insert(uploadJob, remoteFp);
}
m_state = UploadingSmall;
}