本文整理汇总了C++中QFileInfo::refresh方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileInfo::refresh方法的具体用法?C++ QFileInfo::refresh怎么用?C++ QFileInfo::refresh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileInfo
的用法示例。
在下文中一共展示了QFileInfo::refresh方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MoveDirectory
bool GalleryUtil::MoveDirectory(const QFileInfo src, QFileInfo &dst)
{
QDir srcDir(src.absoluteFilePath());
dst = MakeUniqueDirectory(dst);
if (!dst.exists())
{
srcDir.mkdir(dst.absoluteFilePath());
dst.refresh();
}
if (!dst.exists() || !dst.isDir())
return false;
bool ok = true;
QDir dstDir(dst.absoluteFilePath());
srcDir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
QFileInfoList list = srcDir.entryInfoList();
QFileInfoList::const_iterator it = list.begin();
for (; it != list.end(); ++it)
{
const QString fn = it->fileName();
QFileInfo dfi(dstDir, fn);
ok &= Move(*it, dfi);
}
return ok && FileDelete(src);
}
示例2: CopyDirectory
bool GalleryUtil::CopyDirectory(const QFileInfo src, QFileInfo &dst)
{
QDir srcDir(src.absoluteFilePath());
dst = MakeUniqueDirectory(dst);
if (!dst.exists())
{
srcDir.mkdir(dst.absoluteFilePath());
dst.refresh();
}
if (!dst.exists() || !dst.isDir())
return false;
bool ok = true;
QDir dstDir(dst.absoluteFilePath());
QFileInfoList list = srcDir.entryInfoList();
QFileInfoList::const_iterator it = list.begin();
for (; it != list.end(); ++it)
{
const QString fn = it->fileName();
if (fn != "." && fn != "..")
{
QFileInfo dfi(dstDir, fn);
ok &= Copy(*it, dfi);
}
}
return ok;
}
示例3: dirFile
FileInfo RunManager_Util::dirFile(QFileInfo fi)
{
fi.refresh();
return FileInfo(toString(fi.fileName()),
(fi.exists()&&fi.lastModified().isValid())?toDateTime(fi.lastModified()):openstudio::DateTime(),
toString(fi.fileName()), /* The default key is the filename */
toPath(fi.absoluteFilePath()),
fi.exists());
}
示例4: saveImage
bool DkImageContainer::saveImage(const QString& filePath, const QImage saveImg, int compression /* = -1 */) {
QFileInfo saveFile = saveImageIntern(filePath, getLoader(), saveImg, compression);
saveFile.refresh();
qDebug() << "save file: " << saveFile.absoluteFilePath();
return saveFile.exists() && saveFile.isFile();
}
示例5: relocateTracks
void GlobalTrackCache::relocateTracks(
GlobalTrackCacheRelocator* pRelocator) {
if (debugLogEnabled()) {
kLogger.debug()
<< "Relocating tracks";
}
TracksByCanonicalLocation relocatedTracksByCanonicalLocation;
for (auto&&
i = m_tracksByCanonicalLocation.begin();
i != m_tracksByCanonicalLocation.end();
++i) {
const QString oldCanonicalLocation = i->first;
Track* plainPtr = i->second->getPlainPtr();
QFileInfo fileInfo = plainPtr->getFileInfo();
// The file info has to be refreshed, otherwise it might return
// a cached and outdated absolute and canonical location!
fileInfo.refresh();
TrackRef trackRef = TrackRef::fromFileInfo(
fileInfo,
plainPtr->getId());
if (!trackRef.hasCanonicalLocation() && trackRef.hasId() && pRelocator) {
fileInfo = pRelocator->relocateCachedTrack(
trackRef.getId(),
fileInfo);
if (fileInfo != plainPtr->getFileInfo()) {
plainPtr->relocate(fileInfo);
}
trackRef = TrackRef::fromFileInfo(
fileInfo,
trackRef.getId());
}
if (!trackRef.hasCanonicalLocation()) {
kLogger.warning()
<< "Failed to relocate track"
<< oldCanonicalLocation
<< trackRef;
continue;
}
QString newCanonicalLocation = trackRef.getCanonicalLocation();
if (oldCanonicalLocation == newCanonicalLocation) {
// Copy the entry unmodified into the new map
relocatedTracksByCanonicalLocation.insert(*i);
continue;
}
if (debugLogEnabled()) {
kLogger.debug()
<< "Relocating track"
<< "from" << oldCanonicalLocation
<< "to" << newCanonicalLocation;
}
relocatedTracksByCanonicalLocation.insert(std::make_pair(
std::move(newCanonicalLocation),
i->second));
}
m_tracksByCanonicalLocation = std::move(relocatedTracksByCanonicalLocation);
}
示例6: loadImageThreaded
bool DkImageContainerT::loadImageThreaded(bool force) {
#ifdef WITH_QUAZIP
//zip archives: get zip file fileInfo for checks
if(isFromZip())
setFilePath(getZipData()->getZipFilePath());
#endif
// check file for updates
QFileInfo fileInfo = filePath();
QDateTime modifiedBefore = fileInfo.lastModified();
fileInfo.refresh();
if (force || fileInfo.lastModified() != modifiedBefore || getLoader()->isDirty()) {
qDebug() << "updating image...";
getThumb()->setImage(QImage());
clear();
}
// null file?
if (fileInfo.fileName().isEmpty() || !fileInfo.exists()) {
QString msg = tr("Sorry, the file: %1 does not exist... ").arg(fileName());
emit showInfoSignal(msg);
mLoadState = exists_not;
return false;
}
else if (!fileInfo.permission(QFile::ReadUser)) {
QString msg = tr("Sorry, you are not allowed to read: %1").arg(fileName());
emit showInfoSignal(msg);
mLoadState = exists_not;
return false;
}
#ifdef WITH_QUAZIP
//zip archives: use the image file info from now on
if(isFromZip())
setFilePath(getZipData()->getImageFileName());
#endif
mLoadState = loading;
fetchFile();
return true;
}
示例7: test_ksavefile
//.........这里部分代码省略.........
}
QVERIFY( QFile::exists(targetFile) );
QFile::remove(targetFile);
QVERIFY( !QFile::exists(targetFile) );
}
{
//Test some error conditions
KSaveFile saveFile;
QVERIFY( !saveFile.open() ); //no filename
saveFile.setFileName(targetFile);
QVERIFY( saveFile.open() );
QVERIFY( !QFile::exists(targetFile) );
QVERIFY( !saveFile.open() ); //already open
QVERIFY( saveFile.finalize() );
QVERIFY( QFile::exists(targetFile) );
QVERIFY( !saveFile.finalize() ); //already finalized
QFile::remove(targetFile);
QVERIFY( !QFile::exists(targetFile) );
}
{
//Do it again, aborting this time
KSaveFile saveFile ( targetFile );
QVERIFY( saveFile.open() );
QVERIFY( !QFile::exists(targetFile) );
QTextStream ts ( &saveFile );
ts << "This is test data two.\n";
ts.flush();
QCOMPARE( saveFile.error(), QFile::NoError );
QVERIFY( !QFile::exists(targetFile) );
saveFile.abort();
QVERIFY( !QFile::exists(targetFile) );
}
QFile file ( targetFile );
QVERIFY( file.open(QIODevice::WriteOnly | QIODevice::Text) );
QVERIFY( file.setPermissions( file.permissions() | QFile::ExeUser ) );
file.close();
{
//Test how it works when the file already exists
//Also check for special permissions
KSaveFile saveFile ( targetFile );
QVERIFY( saveFile.open() );
QVERIFY( QFile::exists(targetFile) );
QFileInfo fi ( targetFile );
#ifndef Q_WS_WIN
// Windows: qt_ntfs_permission_lookup is not set by default in
// qfsfileengine_win.cpp, could change in future Qt versions.
QVERIFY( fi.permission( QFile::ExeUser ) );
#endif
QVERIFY( fi.size() == 0 );
QTextStream ts ( &saveFile );
ts << "This is test data three.\n";
ts.flush();
fi.refresh();
QVERIFY( fi.size() == 0 );
QVERIFY( saveFile.finalize() );
fi.refresh();
QVERIFY( fi.size() != 0 );
#ifndef Q_WS_WIN
QVERIFY( fi.permission( QFile::ExeUser ) );
#endif
QFile::remove(targetFile);
}
{
QFileInfo fi ( targetFile );
targetFile = fi.fileName();
QDir::setCurrent(fi.path());
//one more time, this time with relative filenames
KSaveFile saveFile ( targetFile );
QVERIFY( saveFile.open() );
QVERIFY( !QFile::exists(targetFile) );
QTextStream ts ( &saveFile );
ts << "This is test data four.\n";
ts.flush();
QCOMPARE( saveFile.error(), QFile::NoError );
QVERIFY( !QFile::exists(targetFile) );
QVERIFY( saveFile.finalize() );
QVERIFY( QFile::exists(targetFile) );
QFile::remove(targetFile);
}
}
示例8: openPath
/*!
\param path The QFileInfo of the path to open (it can be a file, a folder, a symlink,...).
\param source The place where the path was found.
\param sourceIsAContainerFile Indicates if "source" is a container file.
\return Returns a ResultOfOpening value indicating the result of the operation.
*/
TNxSpooler::ResultOfOpening TNxSpooler::openPath(QFileInfo &path, const QString &source, bool /* sourceIsAContainerFile (temporary unused parameter) */) const
{
QDEBUG_METHOD_NAME;
// Object to store the arguments to some callings
QStringList arguments;
// Name of the application that can be used to open the file
QString app;
// Stores the result of opening the path. This will be the value to return
TNxSpooler::ResultOfOpening opResult = TNxSpooler::OpeningError; // It has this default value
// Folders and {paths that do not seem to exist (there are many cases)} are not managed in the next block
if (!path.isDir() && path.exists())
{
// Get the index of the file extension
int i = m_settings.value("exts").toStringList().indexOf(path.suffix());
if (i == -1)
{
// This case can happen if the path to open was inside a container file
syst.showError(tr("2208097 - NxSpooler is not configured to launch an application to open files "
"like \"%1\", which was found inside \"%2\".\n\n"
"The administrator of this computer should see if this is due to a mistake "
"of the program that created the file, an incorrect configuration of "
"NxSpooler, etc.")
.arg(QDir::toNativeSeparators(path.fileName()))
.arg(QDir::toNativeSeparators(source)));
return TNxSpooler::OpeningError;
}
app = m_settings.value("apps").toStringList().value(i);
// There's no problem if app.isEmpty()
#ifdef Q_WS_WIN
arguments << "/C" << "start" << "/wait" << app;
#endif
}
// Note: this way it worked with paths like "smb://server/resource" in Linux
arguments << QDir::toNativeSeparators(path.filePath());
// Folders and {paths that do not seem to exist (there are many cases)} are not managed in the next block
if (path.exists() && !path.isDir())
{
// For avoiding the problem of having a file still being formed
// and trying to open it, we'll wait until it has a stable size
path.setCaching(false); // To try to read the current information about the file
qint64 file_size_in_instant_1, file_size_in_instant_2;
do
{
// Get the size
file_size_in_instant_1 = path.size();
syst.wait(750);
// Refresh the information that we have about the file
path.refresh();
file_size_in_instant_2 = path.size();
} while (file_size_in_instant_1 != file_size_in_instant_2);
// Try to open the file
#ifdef Q_WS_WIN
if (syst.execute("cmd", arguments) == 0)
opResult = TNxSpooler::OpeningOk;
else
opResult = TNxSpooler::OpeningError;
#else
// If the user is using Linux and he has not specified the name of the program to use,
// execute the default program
if (app.isEmpty())
{
if (syst.execute(getDefaultProgramInLinux(), arguments) == 0)
opResult = TNxSpooler::OpeningOk;
else
opResult = TNxSpooler::OpeningError;
}
else
{
if (syst.execute(app, arguments) == 0)
opResult = TNxSpooler::OpeningOk;
else
opResult = TNxSpooler::OpeningError;
}
#endif
}
else
{
// it's a folder, or something that doesn't seem to exist (there are many cases)
//.........这里部分代码省略.........