本文整理汇总了C++中QFileInfo::setCaching方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileInfo::setCaching方法的具体用法?C++ QFileInfo::setCaching怎么用?C++ QFileInfo::setCaching使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileInfo
的用法示例。
在下文中一共展示了QFileInfo::setCaching方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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)
//.........这里部分代码省略.........