本文整理汇总了C++中QFile::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::resize方法的具体用法?C++ QFile::resize怎么用?C++ QFile::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::resize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Supprimer_Session
void MainWindow::Supprimer_Session(QString Nom_Session)
{
int reponse = QMessageBox::question(this, "Vraiment?", "Etes-vous sûr de vouloir supprimer la session "+Nom_Session+" ?", QMessageBox::Yes | QMessageBox::No);
if (reponse == QMessageBox::Yes)
{
//toute la philosophie est de ne modifier que le fichier liste_session et de réinstancier le paramètre F_Accueil !
QFile *fichier = Fenetre_Accueil->get_Liste_Sessions();
fichier->open(QIODevice::ReadWrite | QIODevice::Text);
QTextStream flux(fichier);
QString contenu;
while (!flux.atEnd())
{
QString ligne=flux.readLine();
if (ligne!=Nom_Session)
contenu=contenu.append(ligne+"\n");
}
fichier->resize(0);
fichier->write(contenu.toLatin1(),contenu.size());
fichier->close();
F_Accueil *Nlle_fenetre = new F_Accueil;
Nlle_fenetre->setParent(this);
Nlle_fenetre->move(0,0);
Fenetre_Accueil=Nlle_fenetre;
QObject::connect(Fenetre_Accueil,SIGNAL(Signal_Ouvrir_Session(QString)),this,SLOT(Afficher_Fenetre_Session(QString)));
Retour_Accueil();
}
}
示例2: saveImageFile
void UEFITool::saveImageFile()
{
QString path = QFileDialog::getSaveFileName(this, tr("Save BIOS image file"),".","BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.efi);;All files (*.*)");
if (path.isEmpty())
return;
QByteArray reconstructed;
UINT8 result = ffsEngine->reconstructImageFile(reconstructed);
showMessages();
if (result) {
QMessageBox::critical(this, tr("Image reconstruction failed"), tr("Error code: %1").arg(result), QMessageBox::Ok);
return;
}
QFile outputFile;
outputFile.setFileName(path);
if (!outputFile.open(QFile::WriteOnly)) {
QMessageBox::critical(this, tr("Image reconstruction failed"), tr("Can't open output file for rewriting"), QMessageBox::Ok);
return;
}
outputFile.resize(0);
outputFile.write(reconstructed);
outputFile.close();
if (QMessageBox::information(this, tr("Image reconstruction successful"), tr("Open reconstructed file?"), QMessageBox::Yes, QMessageBox::No)
== QMessageBox::Yes)
openImageFile(path);
}
示例3: exportDoc
//-----------------------------------------------------------------
void Exporter::exportDoc()
{
QTextDocument *document = buildFinalDoc();
if(ui->fileTypeComboBox->currentIndex() == 0)
format = "html";
if(ui->fileTypeComboBox->currentIndex() == 1)
format = "odt";
if(ui->fileTypeComboBox->currentIndex() == 2){
format = "txt";
QMessageBox::information(this, tr("Project Exporter"), tr("You have selected the .txt format. There is no formatting !"), QMessageBox::Ok);
}
QTextDocumentWriter writer;
QByteArray array;
QString fileName(ui->pathLineEdit->text() + "/" + ui->fileNameLineEdit->text() + "." + format);
writer.setFormat(array.append(format));
writer.setFileName(fileName);
writer.setCodec(QTextCodec::codecForName("UTF-8"));
writer.write(document);
if(format=="html"){
QFile *textFile = new QFile;
textFile->setFileName(fileName);
bool opened = textFile->open(QFile::ReadWrite | QFile::Text);
// qDebug() << opened ;
QTextStream textFileStream( textFile );
QString textString(textFileStream.readAll());
if (textFile->resize(0))
{
QRegExp regExpCss("<style type=\x0022text/css\x0022>.*</style>");
regExpCss.setMinimal(true);
textString = textString.replace( regExpCss, "<style type=\x0022text/css\x0022>p, li { white-space: pre-wrap; } p{line-height: 2em; font-family:'Liberation Serif'; font-size:12pt;margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:72px;}</style>");
// qDebug() << textString;
QByteArray array;
array.append(textString);
textFile->write(array);
}
textFile->close();
}
QApplication::restoreOverrideCursor();
QMessageBox::information(this, tr("Project exported"), tr("This project was successfully exported !"), QMessageBox::Ok);
}
示例4: save
bool LoadSaveManager::save(const ILoadSave &loadSave)
{
QFile file {m_configFilePath};
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
qCWarning(QLoggingCategory("load-save-manager")) << "Failed to open config file"
<< m_configFilePath;
return false;
}
QJsonParseError error {-1, QJsonParseError::NoError};
QJsonDocument document {QJsonDocument::fromJson(file.readAll(), &error)};
QJsonObject config {document.object()};
loadSave.save(config);
document.setObject(config);
file.resize(0);
file.write(document.toJson(QJsonDocument::Indented));
file.close();
return true;
}
示例5: writeSparse
void writeSparse(QFile& file, const AttributeMap& data)
{
FNTRACE("ini", "", "writeSparse", QString("file %1, %2 rows of data").arg(file.fileName()).arg(data.size()));
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
ETHROW(Exception(QString("Unable to open %1 for writing.").arg(file.fileName())));
file.resize(0);
QTextStream fout(&file);
int max_key_length = 0;
for (AttributeMap::const_iterator iter = data.begin(); iter != data.end(); ++iter)
{
if (iter.key().length() > max_key_length)
max_key_length = iter.key().length();
}
for (AttributeMap::const_iterator iter = data.begin(); iter != data.end(); ++iter)
{
fout << iter.key();
for (int i = iter.key().length(); i < max_key_length; ++i)
fout << ' ';
fout << " = " << iter.value() << "\n";
}
}
示例6: extract
void UEFITool::extract(const UINT8 mode)
{
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
if (!index.isValid())
return;
TreeModel* model = ffsEngine->treeModel();
UINT8 type = model->type(index);
QString path;
if (mode == EXTRACT_MODE_AS_IS) {
switch (type) {
case Capsule:
path = QFileDialog::getSaveFileName(this, tr("Save capsule to file"),".","Capsule files (*.cap *.bin);;All files (*.*)");
break;
case Image:
path = QFileDialog::getSaveFileName(this, tr("Save image to file"),".","Image files (*.rom *.bin);;All files (*.*)");
break;
case Region:
path = QFileDialog::getSaveFileName(this, tr("Save region to file"),".","Region files (*.rgn *.bin);;All files (*.*)");
break;
case Padding:
path = QFileDialog::getSaveFileName(this, tr("Save padding to file"),".","Padding files (*.pad *.bin);;All files (*.*)");
break;
case Volume:
path = QFileDialog::getSaveFileName(this, tr("Save volume to file"),".","Volume files (*.vol *.bin);;All files (*.*)");
break;
case File:
path = QFileDialog::getSaveFileName(this, tr("Save FFS file to file"),".","FFS files (*.ffs *.bin);;All files (*.*)");
break;
case Section:
path = QFileDialog::getSaveFileName(this, tr("Save section file to file"),".","Section files (*.sct *.bin);;All files (*.*)");
break;
default:
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
}
}
else if (mode == EXTRACT_MODE_BODY) {
switch (type) {
case Capsule:
path = QFileDialog::getSaveFileName(this, tr("Save capsule body to image file"),".","Image files (*.rom *.bin);;All files (*.*)");
break;
case File: {
if (model->subtype(index) == EFI_FV_FILETYPE_ALL || model->subtype(index) == EFI_FV_FILETYPE_RAW)
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to raw file"),".","Raw files (*.raw *.bin);;All files (*.*)");
else
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to file"),".","FFS file body files (*.fbd *.bin);;All files (*.*)");
}
break;
case Section: {
if (model->subtype(index) == EFI_SECTION_COMPRESSION || model->subtype(index) == EFI_SECTION_GUID_DEFINED || model->subtype(index) == EFI_SECTION_DISPOSABLE)
path = QFileDialog::getSaveFileName(this, tr("Save encapsulation section body to FFS body file"),".","FFS file body files (*.fbd *.bin);;All files (*.*)");
else if (model->subtype(index) == EFI_SECTION_FIRMWARE_VOLUME_IMAGE)
path = QFileDialog::getSaveFileName(this, tr("Save section body to volume file"),".","Volume files (*.vol *.bin);;All files (*.*)");
else if (model->subtype(index) == EFI_SECTION_RAW)
path = QFileDialog::getSaveFileName(this, tr("Save section body to raw file"),".","Raw files (*.raw *.bin);;All files (*.*)");
else
path = QFileDialog::getSaveFileName(this, tr("Save section body to file"),".","Binary files (*.bin);;All files (*.*)");
}
break;
default:
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
}
}
else
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
QByteArray extracted;
UINT8 result = ffsEngine->extract(index, extracted, mode);
if (result) {
QMessageBox::critical(this, tr("Extraction failed"), tr("Error code: %1").arg(result), QMessageBox::Ok);
return;
}
QFile outputFile;
outputFile.setFileName(path);
if (!outputFile.open(QFile::WriteOnly)) {
QMessageBox::critical(this, tr("Extraction failed"), tr("Can't open output file for rewriting"), QMessageBox::Ok);
return;
}
outputFile.resize(0);
outputFile.write(extracted);
outputFile.close();
}