当前位置: 首页>>代码示例>>C++>>正文


C++ QFileInfo::setCaching方法代码示例

本文整理汇总了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)
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:nxspooler-svn,代码行数:101,代码来源:tnxspooler.cpp


注:本文中的QFileInfo::setCaching方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。