本文整理汇总了C++中QFileInfo::path方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileInfo::path方法的具体用法?C++ QFileInfo::path怎么用?C++ QFileInfo::path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileInfo
的用法示例。
在下文中一共展示了QFileInfo::path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleFile
void PackageProcessor::HandleFile (int packageId,
const QUrl& url, PackageProcessor::Mode mode)
{
QString path = Core::Instance ()
.GetExtResourceManager ()->GetResourcePath (url);
QProcess *unarch = new QProcess (this);
connect (unarch,
SIGNAL (finished (int, QProcess::ExitStatus)),
this,
SLOT (handlePackageUnarchFinished (int, QProcess::ExitStatus)));
connect (unarch,
SIGNAL (error (QProcess::ProcessError)),
this,
SLOT (handleUnarchError (QProcess::ProcessError)));
QString dirname = Util::GetTemporaryName ("lackman_stagingarea");
QStringList args;
#ifdef Q_WS_WIN
args << "x";
#else
args << "xzf";
#endif
args << path;
#ifdef Q_WS_WIN
args << "-o";
#else
args << "-C";
#endif
args << dirname;
unarch->setProperty ("PackageID", packageId);
unarch->setProperty ("StagingDirectory", dirname);
unarch->setProperty ("Path", path);
unarch->setProperty ("Mode", mode);
QFileInfo sdInfo (dirname);
QDir stagingParentDir (sdInfo.path ());
if (!stagingParentDir.exists (sdInfo.fileName ()) &&
!stagingParentDir.mkdir (sdInfo.fileName ()))
{
qWarning () << Q_FUNC_INFO
<< "unable to create staging directory"
<< sdInfo.fileName ()
<< "in"
<< sdInfo.path ();
QString errorString = tr ("Unable to create staging directory %1.")
.arg (sdInfo.fileName ());
emit packageInstallError (packageId, errorString);
return;
}
#ifdef Q_WS_WIN
QString command = "7za";
#else
QString command = "tar";
#endif
unarch->start (command, args);
}
示例2: copyDirectory
bool JasonQt_File::copyDirectory(const QFileInfo &sourceDirectory, const QFileInfo &targetDirectory, const bool &cover)
{
try
{
if(!sourceDirectory.isDir())
{
throw false;
}
if(sourceDirectory.filePath()[sourceDirectory.filePath().size() - 1] != '/')
{
throw false;
}
if(targetDirectory.filePath()[targetDirectory.filePath().size() - 1] != '/')
{
throw false;
}
JasonQt_File::foreachFileFromDirectory(sourceDirectory, [&](const QFileInfo &info)
{
const auto &&path = info.path().mid(sourceDirectory.path().size());
if(!JasonQt_File::copyFile(info, targetDirectory.path() + "/" + ((path.isEmpty()) ? ("") : (path + "/")) + info.fileName(), cover))
{
throw false;
}
}, true);
}
catch(const bool &error)
{
return error;
}
return true;
}
示例3: hash
void
SoundSettings::suggestedTargetFilePath (
const QString &filePath,
QString &baseDir,
QString &fileName,
QString &xmlFileName)
{
QString subDir;
QFileInfo fileInfo (filePath);
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData (fileInfo.path().toUtf8());
subDir = QString(hash.result().toHex());
subDir.truncate (32);
baseDir = userSaveDir() +
QDir::separator() +
subDir;
fileName = fileInfo.baseName() + "." + fileInfo.completeSuffix();
xmlFileName = fileInfo.baseName() + ".xml";
SYS_DEBUG ("*** baseName() = %s", SYS_STR(fileInfo.baseName()));
SYS_DEBUG ("*** path() = %s", SYS_STR(fileInfo.path()));
SYS_DEBUG ("*** completeSuffix() = %s", SYS_STR(fileInfo.completeSuffix()));
}
示例4: executeFile
void FileBrowser::executeFile()
{
LiteApi::ILiteBuild *build = LiteApi::getLiteBuild(m_liteApp);
if (build) {
QFileInfo info = m_folderView->contextFileInfo();
QString cmd = FileUtil::lookPathInDir(info.fileName(),info.path());
if (!cmd.isEmpty()) {
build->executeCommand(cmd,QString(),info.path(),true,true,false);
}
}
}
示例5: applyConfigured
bool Themes::applyConfigured() {
boost::optional<ThemeInfo::StyleInfo> style = Themes::getConfiguredStyle(g.s);
if (!style) {
return false;
}
const QFileInfo qssFile(style->getPlatformQss());
qWarning() << "Theme:" << style->themeName;
qWarning() << "Style:" << style->name;
qWarning() << "--> qss:" << qssFile.absoluteFilePath();
QFile file(qssFile.absoluteFilePath());
if (!file.open(QFile::ReadOnly)) {
qWarning() << "Failed to open theme stylesheet:" << file.errorString();
return false;
}
QStringList skinPaths;
skinPaths << qssFile.path();
skinPaths << QLatin1String(":/themes/Mumble"); // Some skins might want to fall-back on our built-in resources
QString themeQss = QString::fromUtf8(file.readAll());
setTheme(themeQss, skinPaths);
return true;
}
示例6:
FsItem::FsItem(QFileInfo & info)
{
fullname = info.absoluteFilePath();
path = info.path();
shortname = info.fileName();
isfile = info.isFile();
}
示例7: copyFile
bool JasonQt_File::copyFile(const QFileInfo &sourcePath, const QFileInfo &targetPath, const bool &cover)
{
if(sourcePath.filePath()[sourcePath.filePath().size() - 1] == '/')
{
return false;
}
if(targetPath.filePath()[targetPath.filePath().size() - 1] == '/')
{
return false;
}
if(!targetPath.dir().isReadable())
{
if(!QDir().mkpath(targetPath.path()))
{
return false;
}
}
if(targetPath.isFile() && !cover)
{
return true;
}
return QFile::copy(sourcePath.filePath(), targetPath.filePath());
}
示例8: writeFile
bool JasonQt_File::writeFile(const QFileInfo &targetFilePath, const QByteArray &data, const bool &cover)
{
if(!targetFilePath.dir().isReadable())
{
if(!QDir().mkpath(targetFilePath.path()))
{
return false;
}
}
if(targetFilePath.isFile() && !cover)
{
return true;
}
QFile file(targetFilePath.filePath());
if(!file.open(QIODevice::WriteOnly))
{
return false;
}
file.write(data);
file.waitForBytesWritten(10000);
return true;
}
示例9: tf
PrinterAPI::PrinterAPI() : QObject(COLLECTOR)
{
qDebug() << "PrinterAPI loaded";
setObjectName("printer");
printer = QString("File");
cmd = QString("");
color = true;
useICC = false;
mph = false;
mpv = false;
ucr = true;
copies = true;
QString tf(ScCore->primaryMainWindow()->doc->pdfOptions().fileName);
if (tf.isEmpty())
{
QFileInfo fi = QFileInfo(ScCore->primaryMainWindow()->doc->DocName);
tf = fi.path()+"/"+fi.baseName()+".pdf";
}
file = tf;
int num = 0;
if (ScCore->primaryMainWindow()->HaveDoc)
num = ScCore->primaryMainWindow()->doc->Pages->count();
for (int i = 0; i<num; i++)
{
pages.append(i+1);
}
separation = "No";
}
示例10: ListFilesInDirectoryTest
QMultiMap<QString,FileAttributes> ListFilesInDirectoryTest(QDir dir, bool Hash)
{
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
qt_ntfs_permission_lookup++; // turn checking on
QMultiMap<QString, FileAttributes> fileAttHashTable; //making hash table to store file attributes
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
dir.setSorting(QDir::Name);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i)
{
QFileInfo fileInfo = list.at(i);
if (fileInfo.isFile())
{
FileAttributes tempFileAttributes;
QDateTime date = fileInfo.lastModified();
QString lastModified = date.toString();
tempFileAttributes.absoluteFilePath = fileInfo.absoluteFilePath();
tempFileAttributes.fileName = fileInfo.fileName();
tempFileAttributes.filePath= fileInfo.path();
if (Hash) tempFileAttributes.md5Hash = GetFileMd5hash(fileInfo.absoluteFilePath());
tempFileAttributes.lastModified = fileInfo.lastModified();
tempFileAttributes.lastRead = fileInfo.lastRead();
tempFileAttributes.created = fileInfo.created();
tempFileAttributes.isHidden = fileInfo.isHidden();
tempFileAttributes.size = fileInfo.size();
tempFileAttributes.owner = fileInfo.owner();
fileAttHashTable.insert(fileInfo.absoluteFilePath(),tempFileAttributes);
}
}
return fileAttHashTable;
}
示例11: saveSubtitles
void TabDivePhotos::saveSubtitles()
{
QVector<QString> selectedPhotos;
if (!ui->photosView->selectionModel()->hasSelection())
return;
QModelIndexList indexes = ui->photosView->selectionModel()->selectedRows();
if (indexes.count() == 0)
indexes = ui->photosView->selectionModel()->selectedIndexes();
selectedPhotos.reserve(indexes.count());
for (const auto &photo: indexes) {
if (photo.isValid()) {
QString fileUrl = photo.data(Qt::DisplayPropertyRole).toString();
if (!fileUrl.isEmpty()) {
QFileInfo fi = QFileInfo(fileUrl);
QFile subtitlefile;
subtitlefile.setFileName(QString(fi.path()) + "/" + fi.completeBaseName() + ".ass");
int offset = photo.data(Qt::UserRole + 1).toInt();
int duration = photo.data(Qt::UserRole + 2).toInt();
// Only videos have non-zero duration
if (!duration)
continue;
struct membuffer b = { 0 };
save_subtitles_buffer(&b, &displayed_dive, offset, duration);
char *data = detach_buffer(&b);
subtitlefile.open(QIODevice::WriteOnly);
subtitlefile.write(data, strlen(data));
subtitlefile.close();
free(data);
}
}
}
}
示例12: loadBackup
void RepoEditor::loadBackup()
{
RepoConf conf;
QFileInfo fi;
QString file;
if (!ui->backupFile->text().isEmpty())
{
fi.setFile(ui->backupFile->text());
file = QFileDialog::getOpenFileName( this, "Open file", fi.path() );
}
else
file = QFileDialog::getOpenFileName( this );
if( file.isEmpty() )
return;
conf.loadConf( file );
if( !conf.count() ) {
QMessageBox mb(QMessageBox::Critical,
tr( "Can't load backup file" ),
tr( "Selected file is not valid" ),
QMessageBox::Ok,
this);
mb.exec();
} else {
repoConf->loadConf( file );
ui->backupFile->setText( repoConf->getConfPath() + ".bak" );
}
}
示例13: toNativeSeparators
// +-----------------------------------------------------------
QString ft::Utils::shortenPath(const QString &sPath, int iMaxLen)
{
// If the string is not long enough, simply return it
if(sPath.length() <= iMaxLen)
return QDir::toNativeSeparators(sPath);
QFileInfo oFile = QFileInfo(sPath);
QString sPathOnly = oFile.path();
QString sFileName = QDir::separator() + oFile.fileName();
QString sDriveLetter = ""; // In case it is running on a Windows OS
// Firstly, split the path (only) into parts (for the drive letter and/or each subfolder)
QRegExp oRegex("([\\\\\\/][\\w -\\.]*)");
QStringList lsParts;
QMultiMap<int, int> mpSortedParts;
QString sPart;
bool bFirst = true;
int iPos = 0;
while((iPos = oRegex.indexIn(sPathOnly, iPos)) != -1)
{
if(bFirst)
{
sDriveLetter = sPathOnly.left(iPos);
bFirst = false;
}
sPart = oRegex.cap(1);
lsParts.push_back(sPart);
mpSortedParts.insert(sPart.length(), lsParts.count() - 1);
iPos += oRegex.matchedLength();
}
// Then, iteratively remove the larger parts while the path is bigger than
// the maximum number of characters desired
QString sNewPath;
do
{
sNewPath = "";
// Rebuild the path replacing the so far larger part for "..."
QMapIterator<int, int> oSorted(mpSortedParts);
oSorted.toBack();
if(oSorted.hasPrevious())
{
int iLength = oSorted.peekPrevious().key();
int iIndex = oSorted.peekPrevious().value();
mpSortedParts.remove(iLength, iIndex);
lsParts.replace(iIndex, QDir::separator() + QString("..."));
for(QStringList::iterator it = lsParts.begin(); it != lsParts.end(); ++it)
sNewPath += *it;
}
} while(sNewPath.length() > 0 && QString(sDriveLetter + sNewPath + sFileName).length() > iMaxLen);
if(sNewPath.length() == 0)
sNewPath = QDir::separator() + QString("...");
return QDir::toNativeSeparators(sDriveLetter + sNewPath + sFileName);
}
示例14: on_treeView_activated
void OpenFileDialog::on_treeView_activated(const QModelIndex &index)
{
if (mDirModel->isDir(index))
{
auto mSelectedDir = mDirModel->filePath(index);
if (mSelectedDir.endsWith(".."))
{
// remove "/.."
mSelectedDir = mSelectedDir.left(mSelectedDir.length()-3);
QFileInfo info = (mSelectedDir);
// get parent directory
mSelectedDir = info.path();
}
setDirectory(mSelectedDir);
mDirModel->setRootPath(getDirectory());
mDirModel->setFilter(QDir::NoDot | QDir::AllEntries);
ui->treeView->setRootIndex(mDirModel->index(getDirectory()));
}
else
{
mSelectedFile = mDirModel->filePath(index);
this->accept();
}
}
示例15: getCurrentCacheSize
void FileStorageWatcherThread::getCurrentCacheSize()
{
mDebug() << "FileStorageWatcher: Creating cache size";
quint64 dataSize = 0;
QString basePath = m_dataDirectory + "/maps";
QDirIterator it( basePath,
QDir::Files | QDir::Writable,
QDirIterator::Subdirectories );
int basePathDepth = basePath.split("/").size();
while( it.hasNext() && !m_willQuit ) {
it.next();
QFileInfo file = it.fileInfo();
// We try to be very careful and just delete images
// FIXME, when vectortiling I suppose also vector tiles will have
// to be deleted
QString suffix = file.suffix().toLower();
QStringList path = file.path().split("/");
// planet/theme/tilelevel should be deeper than 4
if ( ( path.size() > basePathDepth + 3 ) &&
( path[basePathDepth + 2].toInt() >= maxBaseTileLevel ) &&
( ( suffix == "jpg"
|| suffix == "png"
|| suffix == "gif"
|| suffix == "svg" ) ) ) {
dataSize += file.size();
m_filesCache.insert(file.lastModified(), file.absoluteFilePath());
}
}
m_currentCacheSize = dataSize;
}