本文整理汇总了C++中FilePtr::open方法的典型用法代码示例。如果您正苦于以下问题:C++ FilePtr::open方法的具体用法?C++ FilePtr::open怎么用?C++ FilePtr::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePtr
的用法示例。
在下文中一共展示了FilePtr::open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: loadMessageInfo
//------------------------------------------------------------------------------------------
long Radio::loadMessageInfo(void)
{
FullPathFileName messageInfoPath;
FilePtr messageInfoFile;
long result;
char dataLine[512];
char* field;
messageInfoPath.init(soundPath,"radio",".csv");
messageInfoFile = new File;
if (!messageInfoFile)
return -1; //quasit
result = messageInfoFile->open(messageInfoPath);
if (result != NO_ERR)
{
delete messageInfoFile;
return result;
}
messageInfoFile->readLine((MemoryPtr)dataLine, 511); // skip title line
for (long i=0; i<RADIO_MESSAGE_COUNT; i++)
{
result = messageInfoFile->readLine((MemoryPtr)dataLine, 511);
if (!result)
Fatal(0, "Bad Message Info File");
field = strtok(dataLine, ","); // get past command name
field = strtok(NULL, ",");
if (field)
messageInfo[i].priority = atoi(field);
else
messageInfo[i].priority = 4;
field = strtok(NULL, ",");
if (field)
messageInfo[i].shelfLife = atoi(field);
else
messageInfo[i].shelfLife = 0;
field = strtok(NULL, ",");
if (field && *field != 'x')
messageInfo[i].movieCode = *field;
else
messageInfo[i].movieCode = '\0';
field = strtok(NULL, ",");
if (field)
messageInfo[i].styleCount = atoi(field);
else
messageInfo[i].styleCount = 1;
field = strtok(NULL, ",");
if (field)
messageInfo[i].styleChance[0] = atoi(field);
else
messageInfo[i].styleChance[0] = 0;
field = strtok(NULL, ",");
if (field)
messageInfo[i].styleChance[1] = atoi(field);
else
messageInfo[i].styleChance[1] = 0;
field = strtok(NULL, ",");
if (field)
messageInfo[i].styleChance[2] = atoi(field);
else
messageInfo[i].styleChance[2] = 0;
field = strtok(NULL, ",");
if (field)
messageInfo[i].pilotIdentifiesSelf = (*field == 'y');
else
messageInfo[i].pilotIdentifiesSelf = FALSE;
field = strtok(NULL, ",");
if (field)
messageInfo[i].messageMapping = atoi(field);
else
messageInfo[i].messageMapping = 0;
field = strtok(NULL, ",");
if (field)
{
field = strtok(NULL, ",");
if (field)
{
messageInfo[i].kludgeStyle = (*field == 'x');
}
}
if (!field)
messageInfo[i].kludgeStyle = FALSE;
}
messageInfoFile->close();
delete messageInfoFile;
return NO_ERR;
}