本文整理汇总了C++中QFile::isWritable方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::isWritable方法的具体用法?C++ QFile::isWritable怎么用?C++ QFile::isWritable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::isWritable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prepareToWrite
void DataBlockFile::prepareToWrite()
{
// std::cerr << "DataBlockFile[" << m_fileName << "]: prepareToWrite" << std::endl;
if (!m_file.isWritable()) {
m_file.close();
m_file.open(QIODevice::WriteOnly | QIODevice::Append);
Q_ASSERT(m_file.isWritable());
}
}
示例2: copy
/** \fn copy(QFile&,QFile&,uint)
* \brief Copies src file to dst file.
*
* If the dst file is open, it must be open for writing.
* If the src file is open, if must be open for reading.
*
* The files will be in the same open or close state after
* this function runs as they were prior to this function being called.
*
* This function does not care if the files are actual files.
* For compatibility with pipes and socket streams the file location
* will not be reset to 0 at the end of this function. If the function
* is successful the file pointers will be at the end of the copied
* data.
*
* \param dst Destination QFile
* \param src Source QFile
* \param block_size Optional block size in bytes, must be at least 1024,
* otherwise the default of 16 KB will be used.
* \return bytes copied on success, -1 on failure.
*/
long long copy(QFile &dst, QFile &src, uint block_size)
{
uint buflen = (block_size < 1024) ? (16 * 1024) : block_size;
char *buf = new char[buflen];
bool odst = false, osrc = false;
if (!buf)
return -1LL;
if (!dst.isWritable() && !dst.isOpen())
odst = dst.open(QIODevice::Unbuffered|QIODevice::WriteOnly|QIODevice::Truncate);
if (!src.isReadable() && !src.isOpen())
osrc = src.open(QIODevice::Unbuffered|QIODevice::ReadOnly);
bool ok = dst.isWritable() && src.isReadable();
long long total_bytes = 0LL;
while (ok)
{
long long rlen, wlen, off = 0;
rlen = src.read(buf, buflen);
if (rlen<0)
{
VERBOSE(VB_IMPORTANT, "util.cpp:copy: read error");
ok = false;
break;
}
if (rlen==0)
break;
total_bytes += (long long) rlen;
while ((rlen-off>0) && ok)
{
wlen = dst.write(buf + off, rlen - off);
if (wlen>=0)
off+= wlen;
if (wlen<0)
{
VERBOSE(VB_IMPORTANT, "util.cpp:copy: write error");
ok = false;
}
}
}
delete[] buf;
if (odst)
dst.close();
if (osrc)
src.close();
return (ok) ? total_bytes : -1LL;
}
示例3: file
void XmlSerializable ::
saveAsXml(const QFileInfo& fileinfo, const char* element_tag) const
{
QString s = getAsXml(element_tag);
if (s.isNull()) ntk_throw_exception("Empty xml document.");
QFile file (fileinfo.absoluteFilePath());
qDebug() << fileinfo.absoluteFilePath();
file.open(QFile::WriteOnly);
ntk_throw_exception_if(!file.isWritable(),
"Cannot write into file "
+ fileinfo.absoluteFilePath().toStdString());
file.write(s.toUtf8());
file.close();
}
示例4: writable
bool File::writable(const String& file)
{
QFileInfo fi(file.toQString());
bool tmp = false;
if (fi.exists())
{
tmp = fi.isWritable();
}
else
{
QFile f;
f.setFileName(file.toQString());
f.open(QIODevice::WriteOnly);
tmp = f.isWritable();
f.remove();
}
return tmp;
}
示例5: openSpecFile
void RxDev::openSpecFile(){
const QModelIndex index = ui->treeView_availableNodes->selectionModel()->currentIndex();
QModelIndex seekRoot = index;
while(seekRoot.parent() != QModelIndex())
{
seekRoot = seekRoot.parent();
}
QString filePath = seekRoot.child(0,0).child(0,0).data(Qt::DisplayRole).toString();
//qDebug()<<filePath;
SpecFileParser *specParser = new SpecFileParser;
specParser->nodeParser(filePath);
SpecFileEdit specFile(&specParser->node);
//qDebug()<<QString::fromStdString(specParser->node.type);
specFile.setWindowTitle("Specfile: "+seekRoot.data(Qt::DisplayRole).toString());
bool accept = specFile.exec();
if ((accept)){
QFile file;
file.setFileName(filePath);
file.open(QIODevice::WriteOnly | QIODevice::Text);
if (file.isWritable()){
QString tempContens = specParser->writeSpecFile(&specParser->node);
QTextStream text(&file);
text<<tempContens;
//qDebug()<<"subs "<<specFile.getSubscriptions();
file.close();
QMessageBox::information( this, "File written!", "The file "+filePath+" was updated\n", QMessageBox::Ok, 0 );
on_pushButton_refreshNodesOrComps_clicked();
} else
QMessageBox::critical(this, "File is write protected!", "The file "+filePath+" could not get updated\n", QMessageBox::Ok, 0 );
// setType(nodeEdit.getType());
// setName(nodeEdit.getName());
// setArgs(nodeEdit.getArgs());
}
// QDesktopServices::openUrl(QUrl::fromLocalFile( filePath));
}
示例6: Write
bool FormattedTouchstone::Write(FormattedNetworkData &network, QString filename) {
QFile file;
CreateFile(file, filename, network);
if (file.isWritable() == false) {
if (file.isOpen()) file.close();
return(false);
}
//else
QTextStream snpFile(&file);
WriteComments(network, snpFile);
WriteOptions(network, snpFile);
if (network.numberOfPorts() != 2)
WriteData(network, snpFile);
else {
FormattedNetworkData copyNetwork = network;
Flip2Ports(copyNetwork);
WriteData(copyNetwork, snpFile);
}
snpFile.flush();
file.close();
return(true);
}
示例7: connected
ClientSocketOpt::ClientSocketOpt(QObject *parent) : QObject(parent)
{
timerid = -1;
recvCounts = 0;
socket = nullptr;
socketThread = new QThread;
socketThread->setObjectName("client socket thread");
this->moveToThread(socketThread);
connect(socketThread, &QThread::finished, this, [=] () {
this->deleteLater();
socketThread->deleteLater();
});
connect(this, &ClientSocketOpt::connectHost,
this, [=] (QString ip, quint16 port) {
socket = new QTcpSocket(this);
connect(socket, &QTcpSocket::connected,
this, [=] () {
// connected
emit connected();
});
socket->connectToHost(ip, port);
if (!socket->waitForConnected())
{
emit recvInformation(cn("接收终止"));
emit disconnected();
socketThread->quit();
return;
}
QFile *file = new QFile(this);
TcpDataDeal *deal = new TcpDataDeal(this);
MessageDataDeal *msg = new MessageDataDeal(this);
connect(deal, &TcpDataDeal::fullFrameData,
msg, &MessageDataDeal::ParserFrameData);
connect(msg, &MessageDataDeal::recvMessageData,
this, [=] (MessageData data) {
if (data.datatype() != FileSendType &&
data.datatype() != commonStr)
return;
if (data.datatype() == commonStr)
{
MessageCharData *charconent = dynamic_cast<MessageCharData*>(data.content());
if (charconent && charconent->type() == FileInfo)
{
QString strinfo = QString::fromLocal8Bit(charconent->content());
emit recvInformation(strinfo);
}
return;
}
// write file
FileDataContent *content = dynamic_cast<FileDataContent*>(data.content());
if (!content)
return;
FileDataContent::FileHead *head = content->sendInfo();
FileDataContent::FileNameHead *namehead = content->fileName();
emit recvProgress(head->totalProgress >= 100 ? 99 : head->totalProgress, head->currentProgress / 100.0);
QString filename = namehead->name.replace(namehead->path, savePath + "/");
QFileInfo info(filename);
emit recvInformation(cn("正在接收 %1").arg(info.fileName()));
QDir dir(info.absolutePath());
if (!dir.exists())
dir.mkpath(info.absolutePath());
if (file->fileName() != filename)
{
file->close();
if (info.exists())
{
QString dt = QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
filename = info.absolutePath() + "/" +
info.bundleName() + dt + "." + info.suffix();
}
file->setFileName(filename);
}
if (!file->isOpen())
{
file->open(QIODevice::WriteOnly | QIODevice::Append);
}
if (file->isWritable())
{
file->write(content->data(), head->fileCurrentSize);
if (head->currentProgress == 100)
file->close();
}
if (socketThread->isInterruptionRequested())
{
emit recvInformation(cn("接收终止"));
file->close();
socket->disconnectFromHost();
socket->abort();
socketThread->quit();
}
if (head->currentProgress == 100 && head->totalProgress == 100)
{
file->close();
emit recvProgress(100, 1);
emit recvInformation(cn("接收完成"));
//.........这里部分代码省略.........