本文整理汇总了C++中QTemporaryFile::setPermissions方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::setPermissions方法的具体用法?C++ QTemporaryFile::setPermissions怎么用?C++ QTemporaryFile::setPermissions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::setPermissions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start
bool ItemEditor::start()
{
// create temp file
const QString tmpFileName = QString("CopyQ.XXXXXX") + getFileSuffixFromMime(m_mime);
QString tmpPath = QDir( QDir::tempPath() ).absoluteFilePath(tmpFileName);
QTemporaryFile tmpfile;
tmpfile.setFileTemplate(tmpPath);
tmpfile.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
if ( !tmpfile.open() ) {
printError( tr("Failed to open temporary file (%1) for editing item in external editor!")
.arg(tmpfile.fileName()) );
return false;
}
// write text to temp file
tmpfile.write(m_data);
tmpfile.flush();
// monitor file
m_info.setFile( tmpfile.fileName() );
m_lastmodified = m_info.lastModified();
m_lastSize = m_info.size();
m_timer->start(500);
connect( m_timer, SIGNAL(timeout()),
this, SLOT(onTimer()) );
// create editor process
m_editor = new QProcess(this);
connect( m_editor, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(close()) );
connect( m_editor, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(onError()) );
// use native path for filename to edit and escape all backslashes
const QString nativeFilePath = QDir::toNativeSeparators(m_info.filePath());
QString cmd = m_editorcmd.arg('"' + nativeFilePath + '"');
cmd.replace("\\", "\\\\");
// execute editor
m_editor->start(cmd);
tmpfile.setAutoRemove(false);
tmpfile.close();
return true;
}
示例2: slotOpen
void KoVersionDialog::slotOpen()
{
if (!list->currentItem())
return;
KoVersionInfo *version = 0;
for (int i = 0; i < m_doc->versionList().size(); ++i) {
if (m_doc->versionList().at(i).date.toString() == list->currentItem()->text(0)) {
version = &m_doc->versionList()[i];
break;
}
}
if (!version)
return;
QTemporaryFile tmp;
tmp.setAutoRemove(false);
tmp.open();
tmp.write(version->data);
tmp.flush();
tmp.setPermissions(QFile::ReadUser);
tmp.flush();
if (!m_doc->documentPart()->mainWindows().isEmpty()) { //open the version in a new window if possible
KoDocumentEntry entry = KoDocumentEntry::queryByMimeType(m_doc->nativeOasisMimeType());
if (entry.isEmpty()) {
entry = KoDocumentEntry::queryByMimeType(m_doc->nativeFormatMimeType());
}
Q_ASSERT(!entry.isEmpty());
QString errorMsg;
KoPart *part= entry.createKoPart(&errorMsg);
if (!part) {
if (!errorMsg.isEmpty())
KMessageBox::error(0, errorMsg);
return;
}
KoMainWindow *mainWindow = part->createMainWindow();
mainWindow ->openDocument(QUrl::fromLocalFile(tmp.fileName()));
mainWindow ->show();
} else {
m_doc->openUrl(QUrl::fromUserInput(tmp.fileName()));
}
tmp.setAutoRemove(true);
slotButtonClicked(Close);
}