本文整理汇总了C++中QFileInfoList::first方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileInfoList::first方法的具体用法?C++ QFileInfoList::first怎么用?C++ QFileInfoList::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileInfoList
的用法示例。
在下文中一共展示了QFileInfoList::first方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QFileInfo
/* Return the first file matching the pattern
* "extensions/<id>/<id><extension-apiversion-mejor>.*". For the
* "dummy" extension using API version 1.2, this means
* "extensions/dummy/dummy1.*". In other words: Extensions must
* provide exactly one file matching this pattern, and that file must
* contain root class/function of the extension.
*
* Scripted extensions with the root class inlined in the XML file are
* not affected by this restriction.
*
* Returns QFileInfo() if no such file was found.
*/
QFileInfo
Configuration::extensionRootFile(const QString &id,
const VersionNumber &apiVersion) const
{
QFileInfoList candidateFiles;
QString pattern = id + QString::number(apiVersion.majorVersion()) + ".*";
// Check the user extension repository first.
QDir base = PlatformDependent::p()->extensionsDir(PlatformDependent::User);
base.cd(id);
candidateFiles = base.entryInfoList(QStringList(pattern),
QDir::Files | QDir::Readable);
// If there were no such files in the user extension repository,
// check the system repository.
if (candidateFiles.isEmpty())
{
base = PlatformDependent::p()->extensionsDir(PlatformDependent::System);
base.cd(id);
candidateFiles = base.entryInfoList(QStringList(pattern),
QDir::Files | QDir::Readable);
}
if (candidateFiles.isEmpty())
return QFileInfo();
else
return candidateFiles.first();
}
示例2: onUpload
/*
Called when the "upload" action is triggered.
Build the current project and upload the resulting .bin to the board.
*/
void MainWindow::onUpload( )
{
if(currentProject.isEmpty())
return statusBar()->showMessage( "Open a project to upload, or create a new one from the File menu.", 3500 );
QDir projectDir(currentProject);
projectDir.cd("build");
projectDir.setNameFilters(QStringList() << "*.bin");
QFileInfoList bins = projectDir.entryInfoList();
if(bins.count())
uploadFile(bins.first().filePath());
else
return statusBar()->showMessage( "Couldn't find the file to upload for this project.", 3500 );
}
示例3: getPrefixIcon
QIcon MainMenu::getPrefixIcon(const QString &prefixHash) const
{
QString iconPath = FS::prefix(prefixHash).absoluteFilePath(".icon");
if (!QFile::exists(iconPath))
{
QFileInfoList iList = FS::icons(prefixHash).entryInfoList(QDir::Files);
if (!iList.isEmpty())
{
QFile::copy(iList.first().absoluteFilePath(), iconPath);
return QIcon(iconPath);
}
return style()->standardIcon(QStyle::SP_DirIcon);
}
return QIcon(iconPath);
}
示例4: deleteFiles
void LogTraceListener::deleteFiles(int days)
{
if(qApp == NULL)
return;
QDir dir(qApp->tr(_logPath.c_str()));
if(dir.exists())
{
string filter = "*.log";
#if WIN32
WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
// Find the first file in the directory.
hFind = FindFirstFile((_logPath + "/" + filter).c_str(), &ffd);
if (INVALID_HANDLE_VALUE != hFind)
{
// List all the files in the directory with some info about them.
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
}
else
{
removeFile(dir, ffd.cFileName, days);
}
}
while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
}
#else
dir.setNameFilter(filter.c_str());
QFileInfoList* list = (QFileInfoList*)dir.entryInfoList();
if(list != NULL)
{
QFileInfo *fi;
for ( fi=list->first(); fi != 0; fi=list->next() )
{
removeFile(dir, Convert::convertStr(fi->fileName()), days);
}
}
#endif
}
}
示例5: fi
//! [4]
QXmlNodeModelIndex
FileTree::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &nodeIndex) const
{
const QFileInfo fi(toFileInfo(nodeIndex));
const Type type = Type(nodeIndex.additionalData());
if (type != File && type != Directory) {
Q_ASSERT_X(axis == Parent, Q_FUNC_INFO, "An attribute only has a parent!");
return toNodeIndex(fi, Directory);
}
switch (axis) {
case Parent:
return toNodeIndex(QFileInfo(fi.path()), Directory);
case FirstChild:
{
if (type == File) // A file has no children.
return QXmlNodeModelIndex();
else {
Q_ASSERT(type == Directory);
Q_ASSERT_X(fi.isDir(), Q_FUNC_INFO, "It isn't really a directory!");
const QDir dir(fi.absoluteFilePath());
Q_ASSERT(dir.exists());
const QFileInfoList children(dir.entryInfoList(QStringList(),
m_filterAllowAll,
m_sortFlags));
if (children.isEmpty())
return QXmlNodeModelIndex();
const QFileInfo firstChild(children.first());
return toNodeIndex(firstChild);
}
}
case PreviousSibling:
return nextSibling(nodeIndex, fi, -1);
case NextSibling:
return nextSibling(nodeIndex, fi, 1);
}
Q_ASSERT_X(false, Q_FUNC_INFO, "Don't ever get here!");
return QXmlNodeModelIndex();
}
示例6: checkSystem
void SysStatus::checkSystem(bool checkjails){
complete = QFile::exists("/tmp/.rebootRequired");
if(!complete){
//Get all the possible flag files and only take the most recent (latest flag - they overwrite each other)
QStringList upinfo = pcbsd::Utils::runShellCommand("syscache needsreboot isupdating");
if(upinfo.length() < 2 || upinfo.join("").contains("[ERROR]") ){
//Fallback method in case syscache is not working for some reason
QDir procdir(UPDATE_PROC_DIR);
QFileInfoList files = procdir.entryInfoList(QStringList() << UPDATE_PROC_FLAG_FILE_FILTER, QDir::Files, QDir::Time);
QStringList tmp; for(int i=0; i<files.length(); i++){ tmp << files[i].absoluteFilePath(); }
QString flag;
if(!files.isEmpty()){ flag = pcbsd::Utils::readTextFile(files.first().absoluteFilePath()).simplified().toLower(); }
//qDebug() << "No syscache running - use flags:" << tmp << flag;
complete = (UPDATE_PROC_FINISHED == flag );
updating = (UPDATE_PROC_WORKING == flag );
}else{
//Use the syscache info
complete = (upinfo[0]=="true");
updating = (upinfo[1]=="true");
}
if(!updating && !complete){
//Run syscache to probe for updates that are available
QString cmd = "syscache hasmajorupdates hassecurityupdates haspcbsdupdates \"pkg #system hasupdates\" \"jail list\"";
QStringList info = pcbsd::Utils::runShellCommand(cmd);
if(info.length() < 5){ return; } //no info from syscache
sys = (info[0] == "true");
sec = (info[1] == "true") || (info[2] == "true"); //combine security updates with pcbsd patches for notifications
pkg = (info[3] == "true");
//Now look for jail updates
if(checkjails && !info[4].simplified().isEmpty() ){
QStringList jls = info[4].split(", ");
cmd = "syscache";
for(int i=0; i<jls.length(); i++){
cmd.append(" \"pkg "+jls[i]+" hasupdates\"");
}
QStringList jinfo = pcbsd::Utils::runShellCommand(cmd);
jail = jinfo.contains("true");
}
}
}
}
示例7: sdcardFolder
QString FolderListModel::sdcardFolder() const
{
QString sdcardfolder;
if(QFile::exists("/media/sdcard"))
sdcardfolder = "/media/sdcard";
if(QFile::exists("/run/user/100000/media/sdcard"))
sdcardfolder = "/run/user/100000/media/sdcard";
if(sdcardfolder.isEmpty())
return QString();
QDir dir(sdcardfolder);
QFileInfoList fileinfolist = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks, QDir::DirsFirst);
if(fileinfolist.isEmpty())
return QString();
return fileinfolist.first().filePath();
}
示例8: init
void StrainPipeData::init()
{
QFileInfo recipefi(directory.absoluteFilePath() + "/logdir/1.RECIPEFILE");
recipefi.exists() ? recipie.reset(new RecipieList(recipefi))
: recipie.reset(new RecipieList());
base_dir.setNameFilters(QStringList("metric_*quast.csv"));
QFileInfoList quastFiles=base_dir.entryInfoList();
quastFiles.empty() ? questMetrics.reset(new QuastMetrics())
: questMetrics.reset(new QuastMetrics(quastFiles.first()));
base_dir.setNameFilters(QStringList("metric_*cgal.csv"));
QFileInfoList cgalFiles = base_dir.entryInfoList();
cgalFiles.empty() ? cgalMetrics.reset(new CgalMetrics())
: cgalMetrics.reset(new CgalMetrics(cgalFiles.first()));
base_dir.setNameFilters(QStringList("metric_*ale.csv"));
QFileInfoList aleFiles=base_dir.entryInfoList();
aleFiles.empty() ? aleMetrics.reset(new AleMetrics())
: aleMetrics.reset(new AleMetrics(aleFiles.first()));
QString timesFilename = base_dir.absolutePath()
+ "/logdir/1stats/allstats.csv";
QFileInfo tfi(timesFilename);
tfi.exists() ? runTimes.reset(new RunTimes(tfi
, base_dir.dirName()
, directory.absolutePath()))
: runTimes.reset(new RunTimes());
// register the plot document object (only needed once, no matter how many
// plots will be in the QTextDocument):
QCPDocumentObject *plotObjectHandler = new QCPDocumentObject();
QTextDocument::documentLayout()->
registerHandler(QCPDocumentObject::PlotTextFormat, plotObjectHandler);
}
示例9: initAacEncImpl
void InitAacEncTask::initAacEncImpl(const char *const toolName, const char *const fileNames[], const quint32 &toolMinVersion, const quint32 &verDigits, const quint32 &verShift, const char *const verStr, QRegExp ®ExpVer, QRegExp ®ExpSig)
{
static const size_t MAX_FILES = 8;
const QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
QFileInfoList fileInfo;
for(size_t i = 0; fileNames[i] && (fileInfo.count() < MAX_FILES); i++)
{
fileInfo.append(QFileInfo(QString("%1/%2").arg(appPath, QString::fromLatin1(fileNames[i]))));
}
for(QFileInfoList::ConstIterator iter = fileInfo.constBegin(); iter != fileInfo.constEnd(); iter++)
{
if(!(iter->exists() && iter->isFile()))
{
qDebug("%s encoder binaries not found -> Encoding support will be disabled!\n", toolName);
return;
}
if((iter->suffix().compare("exe", Qt::CaseInsensitive) == 0) && (!MUtils::OS::is_executable_file(iter->canonicalFilePath())))
{
qDebug("%s executable is invalid -> %s support will be disabled!\n", MUTILS_UTF8(iter->fileName()), toolName);
return;
}
}
qDebug("Found %s encoder binary:\n%s\n", toolName, MUTILS_UTF8(fileInfo.first().canonicalFilePath()));
//Lock the encoder binaries
QScopedPointer<LockedFile> binaries[MAX_FILES];
try
{
size_t index = 0;
for(QFileInfoList::ConstIterator iter = fileInfo.constBegin(); iter != fileInfo.constEnd(); iter++)
{
binaries[index++].reset(new LockedFile(iter->canonicalFilePath()));
}
}
catch(...)
{
qWarning("Failed to get excluive lock to encoder binary -> %s support will be disabled!", toolName);
return;
}
QProcess process;
MUtils::init_process(process, fileInfo.first().absolutePath());
process.start(fileInfo.first().canonicalFilePath(), QStringList() << "-help");
if(!process.waitForStarted())
{
qWarning("%s process failed to create!", toolName);
qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
process.kill();
process.waitForFinished(-1);
return;
}
quint32 toolVersion = 0;
bool sigFound = regExpSig.isEmpty() ? true : false;
while(process.state() != QProcess::NotRunning)
{
if(!process.waitForReadyRead())
{
if(process.state() == QProcess::Running)
{
qWarning("%s process time out -> killing!", toolName);
process.kill();
process.waitForFinished(-1);
return;
}
}
while(process.canReadLine())
{
QString line = QString::fromUtf8(process.readLine().constData()).simplified();
if((!sigFound) && regExpSig.lastIndexIn(line) >= 0)
{
sigFound = true;
continue;
}
if(sigFound && (regExpVer.lastIndexIn(line) >= 0))
{
quint32 tmp[8];
if(MUtils::regexp_parse_uint32(regExpVer, tmp, qMin(verDigits, 8U)))
{
toolVersion = 0;
for(quint32 i = 0; i < verDigits; i++)
{
toolVersion = (toolVersion * verShift) + qBound(0U, tmp[i], (verShift - 1));
}
}
}
}
}
if(toolVersion <= 0)
{
qWarning("%s version could not be determined -> Encoding support will be disabled!", toolName);
return;
}
//.........这里部分代码省略.........
示例10: installPackage
bool PackageJobThread::installPackage(const QString &src, const QString &dest, OperationType operation)
{
QDir root(dest);
if (!root.exists()) {
QDir().mkpath(dest);
if (!root.exists()) {
d->errorMessage = i18n("Could not create package root directory: %1", dest);
d->errorCode = Package::JobError::RootCreationError;
//qWarning() << "Could not create package root directory: " << dest;
return false;
}
}
QFileInfo fileInfo(src);
if (!fileInfo.exists()) {
d->errorMessage = i18n("No such file: %1", src);
d->errorCode = Package::JobError::PackageFileNotFoundError;
return false;
}
QString path;
QTemporaryDir tempdir;
bool archivedPackage = false;
if (fileInfo.isDir()) {
// we have a directory, so let's just install what is in there
path = src;
// make sure we end in a slash!
if (!path.endsWith('/')) {
path.append('/');
}
} else {
KArchive *archive = 0;
QMimeDatabase db;
QMimeType mimetype = db.mimeTypeForFile(src);
if (mimetype.inherits(QStringLiteral("application/zip"))) {
archive = new KZip(src);
} else if (mimetype.inherits(QStringLiteral("application/x-compressed-tar")) ||
mimetype.inherits(QStringLiteral("application/x-tar")) ||
mimetype.inherits(QStringLiteral("application/x-bzip-compressed-tar")) ||
mimetype.inherits(QStringLiteral("application/x-xz")) ||
mimetype.inherits(QStringLiteral("application/x-lzma"))) {
archive = new KTar(src);
} else {
//qWarning() << "Could not open package file, unsupported archive format:" << src << mimetype.name();
d->errorMessage = i18n("Could not open package file, unsupported archive format: %1 %2", src, mimetype.name());
d->errorCode = Package::JobError::UnsupportedArchiveFormatError;
return false;
}
if (!archive->open(QIODevice::ReadOnly)) {
//qWarning() << "Could not open package file:" << src;
delete archive;
d->errorMessage = i18n("Could not open package file: %1", src);
d->errorCode = Package::JobError::PackageOpenError;
return false;
}
archivedPackage = true;
path = tempdir.path() + '/';
d->installPath = path;
const KArchiveDirectory *source = archive->directory();
source->copyTo(path);
QStringList entries = source->entries();
if (entries.count() == 1) {
const KArchiveEntry *entry = source->entry(entries[0]);
if (entry->isDirectory()) {
path.append(entry->name()).append("/");
}
}
delete archive;
}
QDir packageDir(path);
QFileInfoList entries = packageDir.entryInfoList(*metaDataFiles);
KPluginMetaData meta;
if (!entries.isEmpty()) {
const QString metadataFilePath = entries.first().filePath();
if (metadataFilePath.endsWith(QLatin1String(".desktop")))
meta = KPluginMetaData(metadataFilePath);
else {
QFile f(metadataFilePath);
if(!f.open(QIODevice::ReadOnly)){
qWarning() << "Couldn't open metadata file" << src << path;
d->errorMessage = i18n("Could not open metadata file: %1", src);
d->errorCode = Package::JobError::MetadataFileMissingError;
return false;
}
QJsonObject metadataObject = QJsonDocument::fromJson(f.readAll()).object();
meta = KPluginMetaData(metadataObject, QString(), metadataFilePath);
}
}
if (!meta.isValid()) {
qDebug() << "No metadata file in package" << src << path;
d->errorMessage = i18n("No metadata file in package: %1", src);
//.........这里部分代码省略.........
示例11: while
FileList *Computer::getFileList(QString filter)
{
FileList *fileList = new FileList;
QFileInfoList list = this->directory.entryInfoList();
QFileIconProvider *provider;
QStringList date;
QString tmp;
while (!list.isEmpty())
{
date=list.first().lastModified().toString().split(" ");
tmp=date.at(2)+" "+date.at(1)+" "+date.at(4);
tmp.remove(".");
fileList->date.append(tmp);
fileList->name.append(list.first().fileName());
fileList->size.append(QString::number(list.first().size()));
provider=new QFileIconProvider;
fileList->icon.append(provider->icon(list.first()));
if (list.first().isDir())
fileList->type.append("dir");
else
{
if (!fileList->name.last().contains(filter))
{
fileList->date.removeLast();
fileList->name.removeLast();
fileList->size.removeLast();
fileList->icon.removeLast();
}
fileList->type.append("file");
}
delete provider;
list.removeFirst();
}
if (fileList->name.length()==0)
return fileList;
//usun . i ..
if (fileList->name.count()>0)
{
// if (fileList.name.first()==".")
// {
int x=fileList->name.indexOf(".");
if (x!=-1)
{
fileList->date.removeAt(x);
fileList->name.removeAt(x);
fileList->size.removeAt(x);
fileList->type.removeAt(x);
fileList->icon.removeAt(x);
}
x=fileList->name.indexOf("..");
if (x!=-1)
{
fileList->date.removeAt(x);
fileList->name.removeAt(x);
fileList->size.removeAt(x);
fileList->type.removeAt(x);
fileList->icon.removeAt(x);
}
}
return fileList;
}