本文整理汇总了C++中QFileInfo::size方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileInfo::size方法的具体用法?C++ QFileInfo::size怎么用?C++ QFileInfo::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileInfo
的用法示例。
在下文中一共展示了QFileInfo::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeletePathFile
void CMainWindow::DeletePathFile(QString strFilePath)
{
QString strPath = strFilePath;
qDebug()<<strPath;
QDir dir(strPath);
if (!dir.exists())
return ;
dir.setFilter(QDir::Dirs|QDir::Files);
dir.setSorting(QDir::DirsFirst);
QFileInfoList list = dir.entryInfoList();
int i=0;
QString fileName;
do{
QFileInfo fileInfo = list.at(i);
if((fileInfo.fileName()==".")|(fileInfo.fileName()==".."))
{
i++;
continue;
}
bool bisDir=fileInfo.isDir();
if(bisDir)
{
qDebug()<<(QString("%1 %2 %3").arg(fileInfo.size(), 10).arg(fileInfo.fileName(),10).arg(fileInfo.path()))<<fileInfo.absoluteFilePath();
DeletePathFile(fileInfo.filePath());
dir.rmdir(fileInfo.filePath());
}else{
fileName = fileInfo.fileName();
dir.remove(fileInfo.fileName());
qDebug()<<(QString("%1 %2 %3").arg(fileInfo.size(), 10).arg(fileInfo.fileName(),10).arg(fileInfo.path()))<<fileInfo.absoluteFilePath();
}
i++;
}while(i<list.size());
}
示例2: initializePage
void ThirdStep::initializePage ()
{
TotalSize_ = 0;
QString path = field ("RootPath").toString ();
QFileInfo pathInfo (path);
if (pathInfo.isDir ())
{
QDirIterator it (path,
QDirIterator::Subdirectories);
while (it.hasNext ())
{
it.next ();
QFileInfo info = it.fileInfo ();
if (info.isFile () && info.isReadable ())
TotalSize_ += info.size ();
}
}
else if (pathInfo.isFile () &&
pathInfo.isReadable ())
TotalSize_ += pathInfo.size ();
quint64 max = std::log (static_cast<long double> (TotalSize_ / 102400)) * 80;
quint32 pieceSize = 32 * 1024;
int shouldIndex = 0;
for (; TotalSize_ / pieceSize >= max; pieceSize *= 2, ++shouldIndex) ;
if (shouldIndex > PieceSize_->count () - 1)
shouldIndex = PieceSize_->count () - 1;
PieceSize_->setCurrentIndex (shouldIndex);
on_PieceSize__currentIndexChanged ();
}
示例3: getIconPath
QString IconCache::getIconPath(const QString& site)
{
QString cachedName = site;
if (site.contains("http"))
cachedName = QUrl(site).host();
qDebug() << cachedName;
//cachedName = cachedName.replace("http:", "").replace("https:", "").replace("/", "");
QFileInfo info;
info.setFile(cachePath, cachedName + ".png");
if (info.exists())
return info.size() > 0 ? info.absoluteFilePath() : QString();
info.setFile(cachePath, cachedName + ".ico");
if (info.exists())
return info.size() > 0 ? info.absoluteFilePath() : QString();
if (!site.startsWith("http"))
return "";
// Call the main thread to grab the icon in the background
emit findIcon(QUrl("http://" + QUrl(site).host() + "/favicon.ico"));
return "";
}
示例4: carregarRelatorio
//-----------------------------------------------------------
void CrashHandler::carregarRelatorio(const QString &arquivo)
{
ifstream entrada;
QFileInfo fi;
char *buf=NULL;
CaixaMensagem caixa;
//Abre o arquivo .crash
fi.setFile(arquivo);
entrada.open(arquivo);
titulo_lbl->setText(trUtf8("pgModeler crash file analysis"));
criar_btn->setVisible(false);
msg_lbl->clear();
//Caso o arquivo não foi aberto com sucesso, exibe um erro
if(!entrada.is_open())
caixa.show(trUtf8("Error"), Excecao::obterMensagemErro(ERR_PARSERS_ARQDIRNAOCARREGADO).arg(arquivo), CaixaMensagem::ICONE_ERRO);
else
{
QByteArray buf_descomp;
QString buf_aux, str_aux;
int i, idx;
QTextEdit *txt_widgets[]={ acoes_txt, modelo_txt , stack_txt};
//Exibe informações do arquivo
msg_lbl->setText(trUtf8("File: %1\nSize: %2 bytes\n\n").arg(arquivo).arg(fi.size()));
//Cria um buffer no tamanho total do arquivo
buf=new char[fi.size()];
//Le todos os bytes do arquivo
entrada.read(buf, fi.size());
entrada.close();
//Descompacta o buffer lido
buf_descomp.append(buf, fi.size());
buf_descomp=qUncompress(buf_descomp);
//Desaloca o buffer original
delete[](buf);
buf=NULL;
//Obtém o buffer descompactado
buf_aux=QString(buf_descomp.data());
i=idx=0;
//Varre todo o buffer separando jogando cada parte do buffer em sua respectiva seção
while(i < buf_aux.size() && idx <= 2)
{
if(buf_aux.at(i).ascii()!=CHR_DELIMITADOR)
str_aux.append(buf_aux.at(i));
else
{
txt_widgets[idx++]->setPlainText(QString::fromUtf8(str_aux));
str_aux.clear();
}
i++;
}
}
}
示例5: loadReport
void CrashHandler::loadReport(const QString &filename)
{
QFile input;
QFileInfo fi;
char *buf=nullptr;
Messagebox msgbox;
fi.setFile(filename);
input.setFileName(filename);
input.open(QFile::ReadOnly);
title_lbl->setText(trUtf8("pgModeler crash file analysis"));
create_btn->setVisible(false);
msg_lbl->clear();
//Raises an error if the file could not be opened
if(!input.isOpen())
msgbox.show(trUtf8("Error"), Exception::getErrorMessage(ERR_FILE_DIR_NOT_ACCESSED).arg(filename), Messagebox::ERROR_ICON);
else
{
QByteArray uncomp_buf;
QString buf_aux, str_aux;
int i, idx;
QTextEdit *txt_widgets[]={ actions_txt, model_txt , stack_txt};
msg_lbl->setText(trUtf8("File: %1\nSize: %2 bytes\n\n").arg(filename).arg(fi.size()));
//Creates a text buffer
buf=new char[fi.size()];
//Reads the file storing it on the buffer
input.read(buf, fi.size());
input.close();
//Uncompress the buffer
uncomp_buf.append(buf, fi.size());
uncomp_buf=qUncompress(uncomp_buf);
delete[](buf);
buf=nullptr;
buf_aux=QString(uncomp_buf.data());
i=idx=0;
//Showing the sections of the uncompressed buffer on the respective widgets
while(i < buf_aux.size() && idx <= 2)
{
if(buf_aux.at(i).toLatin1()!=CHR_DELIMITER)
str_aux.append(buf_aux.at(i));
else
{
txt_widgets[idx++]->setPlainText(Utf8String::create(str_aux));
str_aux.clear();
}
i++;
}
}
}
示例6: on_actionSave_triggered
/*!
\brief 先清理temp_project中的文件,然后将保存的文件保存在temp_project目录中,然后再将目标目录清理干净,最后将temp_project目录中的文件copy到目标目录中
\fn CMainWindow::on_actionSave_triggered
*/
void CMainWindow::on_actionSave_triggered()
{
emit signal_ClearDebug();
emit signal_ShowMessageDebug(0,QString("开始保存... %1").arg(QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss.zzz")));
///< 清理掉temp_project目录中的文件
QDir tempDir("temp_project");
if (tempDir.exists())
{
qDebug()<<__func__<<__LINE__<<"有";
DeletePathFile(QDir::currentPath()+"/temp_project");
}else
{
qDebug()<<__func__<<__LINE__<<"无";
tempDir.mkdir(QDir::currentPath()+"/temp_project");
}
// qDebug()<<__func__<<__LINE__<<__FILE__<<m_pTreeWidget->topLevelItemCount();
///< 生成配置文件,生成在temp目录中
for (int nTreeItemCount = 0; nTreeItemCount < m_pTreeWidget->topLevelItemCount(); ++nTreeItemCount)
{
if (m_pTreeWidget->topLevelItem(nTreeItemCount)->type() == CGI_SCADA_DLL_I::TreeItemType_Undefined)
{
continue;
}else
{
((CGI_SCADA_DLL_I*)m_pTreeWidget->topLevelItem(nTreeItemCount))->SaveAction();
}
}
DeletePathFile(m_strProjectPath);///< 清理掉目标目录中的文件
/// 将temp_project目录中的文件复制到目标目录
if (!tempDir.exists())
return ;
tempDir.setFilter(QDir::Dirs|QDir::Files);
tempDir.setSorting(QDir::DirsFirst);
QFileInfoList list = tempDir.entryInfoList();
int i=0;
do{
QFileInfo fileInfo = list.at(i);
if((fileInfo.fileName()==".")|(fileInfo.fileName()==".."))
{
i++;
continue;
}
bool bisDir=fileInfo.isDir();
if(bisDir)
{
qDebug()<<(QString("%1 %2 %3").arg(fileInfo.size(), 10).arg(fileInfo.fileName(),10).arg(fileInfo.path()))<<fileInfo.absoluteFilePath();
}else{
qDebug()<<(QString("%1 %2 %3").arg(fileInfo.size(), 10).arg(fileInfo.fileName(),10).arg(fileInfo.path()))<<fileInfo.absoluteFilePath()<<fileInfo.baseName();
QFile::copy(fileInfo.absoluteFilePath(),QString("%1/%2").arg(m_strProjectPath).arg(fileInfo.fileName()));
}
i++;
}while(i<list.size());
emit signal_ShowMessageDebug(0,QString("保存完毕"));
}
示例7: exec
int ModelRestorationForm::exec(void)
{
QStringList file_list=this->getTemporaryModels(), tmp_info;
QFileInfo info;
QTableWidgetItem *item=nullptr;
QFile input;
QString buffer, filename;
QRegExp regexp=QRegExp("(\\<database)( )+(name)(=)(\")");
int start=-1, end=-1, col=0;
while(!file_list.isEmpty())
{
info.setFile(GlobalAttributes::TEMPORARY_DIR, file_list.front());
filename=GlobalAttributes::TEMPORARY_DIR + GlobalAttributes::DIR_SEPARATOR + file_list.front();
input.setFileName(filename);
input.open(QFile::ReadOnly);
buffer.append(input.readAll());
input.close();
start=regexp.indexIn(buffer) + regexp.matchedLength();
end=buffer.indexOf("\"", start);
tmp_info.append(buffer.mid(start, end - start));
tmp_info.append(info.fileName());
tmp_info.append(info.lastModified().toString(QString("yyyy-MM-dd hh:mm:ss")));
if(info.size() < 1024)
tmp_info.append(QString("%1 bytes").arg(info.size()));
else
tmp_info.append(QString("%1 KB").arg(info.size()/1024));
tmp_files_tbw->insertRow(tmp_files_tbw->rowCount());
for(col=0; col < tmp_info.size(); col++)
{
item=new QTableWidgetItem;
item->setText(tmp_info.at(col));
item->setData(Qt::UserRole, filename);
item->setSelected(true);
tmp_files_tbw->setItem(tmp_files_tbw->rowCount()-1, col, item);
}
file_list.pop_front();
buffer.clear();
tmp_info.clear();
start=end=-1;
}
tmp_files_tbw->resizeColumnsToContents();
tmp_files_tbw->resizeRowsToContents();
return(QDialog::exec());
}
示例8: FindFile
void CStart::FindFile()
{
qDebug()<<QDir::currentPath()+"../project";
QString strPath = QDir::currentPath().remove("cgi-bin")+"project";
qDebug()<<strPath;
QDir dir(strPath);
if (!dir.exists())
return ;
dir.setFilter(QDir::Dirs|QDir::Files);
dir.setSorting(QDir::DirsFirst);
QFileInfoList list = dir.entryInfoList();
int i=0;
QString fileName;
do{
QFileInfo fileInfo = list.at(i);
if((fileInfo.fileName()==".")|(fileInfo.fileName()==".."))
{
i++;
continue;
}
bool bisDir=fileInfo.isDir();
if(bisDir)
{
qDebug()<<(QString("%1 %2 %3").arg(fileInfo.size(), 10).arg(fileInfo.fileName(),10).arg(fileInfo.path()))<<fileInfo.absoluteFilePath();
// FindFile(fileInfo.filePath());
}else{
fileName = fileInfo.fileName();
if (fileName.left(3) == "Com")
{
m_ComFileList.append(fileInfo.absoluteFilePath());
}else if (fileName.left(3) == "Net")
{
m_NetFileList.append(fileInfo.absoluteFilePath());
}else if (fileName.left(3) == "Can")
{
m_CANFileList.append(fileInfo.absoluteFilePath());
}else if (fileName == "Information_.xml")
{
InitMonitorIP(fileInfo.absoluteFilePath());
}
qDebug()<<(QString("%1 %2 %3").arg(fileInfo.size(), 10).arg(fileInfo.fileName(),10).arg(fileInfo.path()))<<fileInfo.absoluteFilePath();
}
i++;
}while(i<list.size());
qDebug()<<"m_ComFileList"<<m_ComFileList;
qDebug()<<"m_NetFileList"<<m_NetFileList;
qDebug()<<"m_CANFileList"<<m_CANFileList;
}
示例9: update
bool ScImageCacheFile::update(const QFileInfo & info)
{
bool changed = false;
if (info.lastModified() != m_modified)
{
m_modified = info.lastModified();
changed = true;
}
if (info.size() != m_size)
{
m_size = info.size();
changed = true;
}
return changed;
}
示例10: promptUser
static KUrl promptUser (QWidget *parent, const KUrl& url, const QString& suggestedName)
{
KUrl destUrl;
int result = KIO::R_OVERWRITE;
const QString fileName ((suggestedName.isEmpty() ? url.fileName() : suggestedName));
do {
// convert filename to URL using fromPath to avoid trouble with ':' in filenames (#184202)
destUrl = KFileDialog::getSaveFileName(KUrl::fromPath(fileName), QString(), parent);
if (destUrl.isLocalFile()) {
QFileInfo finfo (destUrl.toLocalFile());
if (finfo.exists()) {
QDateTime now = QDateTime::currentDateTime();
KIO::RenameDialog dlg (parent, i18n("Overwrite File?"), url, destUrl,
KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP),
-1, finfo.size(),
now.toTime_t(), finfo.created().toTime_t(),
now.toTime_t(), finfo.lastModified().toTime_t());
result = dlg.exec();
}
}
} while (result == KIO::R_CANCEL && destUrl.isValid());
return destUrl;
}
示例11: QStandardItem
QList<QStandardItem *> MainWindow::createrowinputtable(QFileInfo fileinfo)
{
QList<QStandardItem *>listitems;
qint64 fs;
QString strfs;
for(int col=0 ; col < inputmodel->columnCount() ; col++)
{
QStandardItem *item = new QStandardItem();
switch(col)
{
case 0:item->setText(fileinfo.fileName());
// add logs,constellations,signals,prns
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
addChildrentofile(item);
break;
case 1: fs = fileinfo.size();
strfs = convertintokbmbgb(fs);
item->setText(strfs);
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
break;
case 2: item->setFlags(item->flags() ^ Qt::ItemIsEditable); //initialize nof ascii logs
break;
case 3: item->setFlags(item->flags() ^ Qt::ItemIsEditable);// initialize no of binary logs
break;
case 4: item->setFlags(item->flags() ^ Qt::ItemIsEditable);//initialize no of unkonwn logs
break;
}
listitems.append(item);
}
return listitems;
}
示例12: data
QVariant FileFilterModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid() || !this->_dir.isReadable())
return QVariant();
if(role == Qt::DisplayRole)
{
QFileInfo fi = this->_files[index.row()];
switch(index.column())
{
case 0:
return fi.fileName();
case 1:
return QString("%1KB").arg(static_cast<qreal>(fi.size()) / 1024.0);
default:
break;
}
}
else if(role == Qt::DecorationRole && index.column() == 0)
return this->_icofile;
return QVariant();
}
示例13: addFileNode
tlp::node addFileNode(const QFileInfo &infos, tlp::Graph *g) {
tlp::node n = g->addNode();
_absolutePaths->setNodeValue(n,tlp::QStringToTlpString(infos.absoluteFilePath()));
_baseNames->setNodeValue(n,tlp::QStringToTlpString(infos.baseName()));
_createdDates->setNodeValue(n,tlp::QStringToTlpString(infos.created().toString()));
_fileNames->setNodeValue(n,tlp::QStringToTlpString(infos.fileName()));
_isDir->setNodeValue(n,infos.isDir());
_isExecutable->setNodeValue(n,infos.isExecutable());
_isReadable->setNodeValue(n,infos.isReadable());
_isSymlink->setNodeValue(n,infos.isSymLink());
_isWritable->setNodeValue(n,infos.isWritable());
_lastModifiedDates->setNodeValue(n,tlp::QStringToTlpString(infos.lastModified().toString()));
_lastReadDates->setNodeValue(n,tlp::QStringToTlpString(infos.lastRead().toString()));
_owners->setNodeValue(n,tlp::QStringToTlpString(infos.owner()));
_permissions->setNodeValue(n,(int)(infos.permissions()));
_suffixes->setNodeValue(n,tlp::QStringToTlpString(infos.suffix()));
_sizes->setNodeValue(n,infos.size());
if (_useIcons) {
std::string extension = infos.suffix().toStdString();
if (infos.isDir()) {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FolderO);
tlp::ColorProperty *viewColor = graph->getProperty<tlp::ColorProperty>("viewColor");
viewColor->setNodeValue(n, dirColor);
}
else if (std::find(commonTextFilesExt.begin(), commonTextFilesExt.end(), extension) != commonTextFilesExt.end()) {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileTextO);
}
else if (std::find(commonArchiveFilesExt.begin(), commonArchiveFilesExt.end(), extension) != commonArchiveFilesExt.end()) {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileArchiveO);
}
else if (std::find(commonAudioFilesExt.begin(), commonAudioFilesExt.end(), extension) != commonAudioFilesExt.end()) {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileAudioO);
}
else if (std::find(commonImageFilesExt.begin(), commonImageFilesExt.end(), extension) != commonImageFilesExt.end()) {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileImageO);
}
else if (std::find(commonVideoFilesExt.begin(), commonVideoFilesExt.end(), extension) != commonVideoFilesExt.end()) {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileVideoO);
}
else if (std::find(commonDevFilesExt.begin(), commonDevFilesExt.end(), extension) != commonDevFilesExt.end()) {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileCodeO);
}
else if (extension == "pdf") {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FilePdfO);
}
else if (extension == "doc" || extension == "docx") {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileWordO);
}
else if (extension == "xls" || extension == "xlsx") {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileExcelO);
}
else if (extension == "ppt" || extension == "pptx") {
_fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FilePowerpointO);
}
}
return n;
}
示例14: getDirSize
/* private slots */
qint64 ShredThread::getDirSize(QString &dir)
{
uint _size = 0;
QDir::Filters flags =
QDir::AllEntries |
QDir::NoDotAndDotDot |
QDir::Hidden |
QDir::System |
QDir::AllDirs;
QDir d;
d.setPath(dir);
QList<QFileInfo> entry = d.entryInfoList(flags);
if ( !entry.isEmpty() ) {
QList<QFileInfo>::const_iterator i;
for ( i=entry.constBegin(); i<entry.constEnd(); i++ ) {
QFileInfo item = *i;
if ( !item.exists() ) continue;
QString path = item.canonicalFilePath();
if ( path==d.absoluteFilePath(dir)
|| item.isSymLink() )
continue;
if ( item.isDir() ) {
_size += getDirSize(path);
} else {
_size += item.size();
};
};
};
return _size;
}
示例15: info
TEST(codegen, DISABLED_file)
{
soft::File file;
QFileInfo info ("/tmp/thermo-edited.dat");
QFile data(info.absoluteFilePath());
if (!data.open(QIODevice::ReadOnly)) {
FAIL();
}
file.filename = info.fileName().toStdString();
file.suffix = info.suffix().toStdString();
file.size = info.size();
auto buffer = data.readAll();
file.data = toStdBlob(buffer);
data.close();
soft::Storage storage("mongo2", "mongodb://localhost", "db=codegentest;coll=filetest");
storage.save(&file);
soft::File filecopy(file.id());
storage.load(&filecopy);
ASSERT_TRUE(filecopy.filename == file.filename);
ASSERT_TRUE(filecopy.suffix == file.suffix);
QTextStream(stdout) << filecopy.data.size() << " -> " << file.data.size() << endl;
ASSERT_TRUE(filecopy.data.size() == file.data.size());
QFile dataCopy(info.absoluteFilePath() + ".copy");
if (!dataCopy.open(QIODevice::WriteOnly |QIODevice::Truncate)) {
FAIL();
}
dataCopy.write((const char*)filecopy.data.data(), (quint64)filecopy.data.size());
}