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


C++ QDir::relativeFilePath方法代码示例

本文整理汇总了C++中QDir::relativeFilePath方法的典型用法代码示例。如果您正苦于以下问题:C++ QDir::relativeFilePath方法的具体用法?C++ QDir::relativeFilePath怎么用?C++ QDir::relativeFilePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDir的用法示例。


在下文中一共展示了QDir::relativeFilePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: resolveLocationIssues

void QrcEditor::resolveLocationIssues(QStringList &files)
{
    const QDir dir = QFileInfo(m_treeview->fileName()).absoluteDir();
    const QString dotdotSlash = QLatin1String("../");
    int i = 0;
    const int count = files.count();
    const int initialCount = files.count();

    // Find first troublesome file
    for (; i < count; i++) {
        QString const &file = files.at(i);
        const QString relativePath = dir.relativeFilePath(file);
        if (relativePath.startsWith(dotdotSlash))
            break;
    }

    // All paths fine -> no interaction needed
    if (i == count) {
        return;
    }

    // Interact with user from now on
    ResolveLocationContext context;
    bool abort = false;
    for (QStringList::iterator it = files.begin(); it != files.end(); ) {
        // Path fine -> skip file
        QString const &file = *it;
        QString const relativePath = dir.relativeFilePath(file);
        if (!relativePath.startsWith(dotdotSlash)) {
            continue;
        }
        // Path troublesome and aborted -> remove file
        bool ok = false;
        if (!abort) {
            // Path troublesome -> query user "Do you want copy/abort/skip".
            QAbstractButton *clickedButton = context.execLocationMessageBox(this, file, initialCount > 1);
            if (clickedButton == context.copyButton) {
                const QFileInfo fi(file);
                QFileInfo suggestion;
                QDir tmpTarget(dir.path() + QString(QDir::separator()) + QString("Resources"));;
                if (tmpTarget.exists())
                    suggestion.setFile(tmpTarget, fi.fileName());
                else
                    suggestion.setFile(dir, fi.fileName());
                // Prompt for copy location, copy and replace name.
                const QString copyName = context.execCopyFileDialog(this, dir, suggestion.absoluteFilePath());
                ok = !copyName.isEmpty() && copyFile(file, copyName, this);
                if (ok)
                    *it = copyName;
            } else if (clickedButton == context.abortButton) {
                abort = true;
            }
        } // !abort
        if (ok) { // Remove files where user canceled or failures occurred.
            ++it;
        } else {
            it = files.erase(it);
        }
    } // for files
}
开发者ID:NoobSaibot,项目名称:qtcreator-minimap,代码行数:60,代码来源:qrceditor.cpp

示例2: savePlsPlaylist

/*******************************************************************************
    .pls playlist save
*******************************************************************************/
void savePlsPlaylist(QIODevice* device, const QDir& playlist_dir, QList<MEDIA::TrackPtr> list)
{
    QTextStream stream(device);
    stream << "[playlist]" << endl;
    stream << "Version=2" << endl;
    stream << "NumberOfEntries=" << list.size() << endl;

    int n = 1;
    foreach (MEDIA::TrackPtr media, list)
    {
      if (!media) continue;
      if (media->type() != TYPE_TRACK && media->type() != TYPE_STREAM) continue;

      // write metadata
      if (media->type() == TYPE_TRACK ) {
        QString media_path = media->url;
        media_path = playlist_dir.relativeFilePath(media_path).toUtf8();

        stream << "File" << n << "=" << media_path << endl;
        stream << "Title" << n << "=" << media->title << endl;
        stream << "Length" << n << "=" << media->duration << endl;
        ++n;
      }
      else { // TYPE_STREAM
        stream << "File" << n << "=" << QString(media->url).toUtf8() << endl;
        stream << "Title" << n << "=" << QString(media->name).toUtf8() << endl;
        stream << "Length" << n << "=" << endl;
        ++n;
      }
    } // fin Foreach
}
开发者ID:RavetcoFX,项目名称:Yarock,代码行数:34,代码来源:playlist_parser.cpp

示例3: saveM3uPlaylist

/*******************************************************************************
    m3u playlist save
*******************************************************************************/
void saveM3uPlaylist(QIODevice* device, const QDir& playlist_dir, QList<MEDIA::TrackPtr> list)
{
    device->write("#EXTM3U\n");

    foreach (MEDIA::TrackPtr media, list)
    {
      if (!media) continue;
      if (media->type() != TYPE_TRACK && media->type() != TYPE_STREAM) continue;

      QString info;
      QString media_path;
      if (media->type() == TYPE_TRACK ) {
        info = QString("#EXTINF:%1,%2 - %3\n").arg(QString::number(media->duration))
                                              .arg(media->artist)
                                              .arg(media->album);
        device->write(info.toUtf8());

        //! Get the path to MediaItem relative to the Playlist File directory
        media_path = playlist_dir.relativeFilePath(media->url);
      }
      else {
        info = QString("#EXTINF:\n");
        info = QString("#EXTINF:%1,%2 - %3\n").arg(0)
                                              .arg("")
                                              .arg(media->name);

        device->write(info.toUtf8());
        media_path = media->url;
      }

    device->write(media_path.toUtf8());
    device->write("\n");
    }
}
开发者ID:RavetcoFX,项目名称:Yarock,代码行数:37,代码来源:playlist_parser.cpp

示例4: migrateDataDir

static void migrateDataDir() {
#ifdef Q_OS_MAC
	QString olddir = QDir::homePath() + QLatin1String("/Library/Preferences/Mumble");
	QString newdir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
	QString linksTo = QFile::readLink(olddir);
	if (!QFile::exists(newdir) && QFile::exists(olddir) && linksTo.isEmpty()) {
		QDir d;
		d.mkpath(newdir + QLatin1String("/.."));
		if (d.rename(olddir, newdir)) {
			if (d.cd(QDir::homePath() + QLatin1String("/Library/Preferences"))) {
				if (QFile::link(d.relativeFilePath(newdir), olddir)) {
					qWarning("Migrated application data directory from '%s' to '%s'",
					         qPrintable(olddir), qPrintable(newdir));
					return;
				}
			}
		}
	} else {
		/* Data dir has already been migrated. */
		return;
	}

	qWarning("Application data migration failed.");
#endif
}
开发者ID:Samangan,项目名称:mumble,代码行数:25,代码来源:Global.cpp

示例5: subdir

QList<QString> scanDir(QDir dir)
{
    QList<QString> files;
    QStack<QString> stack;
    stack.push(dir.absolutePath());
    while (!stack.isEmpty())
    {
      QString sSubdir = stack.pop();
      QDir subdir(sSubdir);

      // Check for the files.
      QList<QString> sublist = subdir.entryList(QDir::Files);
      for (QString& file : sublist)
          file = dir.relativeFilePath(sSubdir + '/' + file);

      files += sublist;

      QFileInfoList infoEntries = subdir.entryInfoList(QStringList(),
                                                       QDir::AllDirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
      for (int i = 0; i < infoEntries.size(); i++)
      {
         QFileInfo& item = infoEntries[i];
         stack.push(item.absoluteFilePath());
      }
    }
    return files;
}
开发者ID:An-dy,项目名称:qTox,代码行数:27,代码来源:main.cpp

示例6: updateTsFiles

static void updateTsFiles( const MetaTranslator& fetchedTor,
                           const QStringList& tsFileNames, const QString& codecForTr,
                           bool noObsolete, bool verbose )
{
    QStringList::ConstIterator t = tsFileNames.begin();
    QDir dir;
    while ( t != tsFileNames.end() ) {
        QString fn = dir.relativeFilePath(*t);
        MetaTranslator tor;
        MetaTranslator out;
        tor.load( *t );
        if ( !codecForTr.isEmpty() )
            tor.setCodec( codecForTr.toLatin1() );
        if ( verbose )
            fprintf( stderr, "Updating '%s'...\n", fn.toLatin1().constData() );
 
        merge( &tor, &fetchedTor, &out, verbose, noObsolete );
        if ( noObsolete )
            out.stripObsoleteMessages();
        out.stripEmptyContexts();
        if ( !out.save(*t) ) {
#if defined(_MSC_VER) && _MSC_VER >= 1400
            char buf[100];
            strerror_s(buf, sizeof(buf), errno);
            fprintf( stderr, "pylupdate4 error: Cannot save '%s': %s\n",
                     fn.toLatin1().constData(), buf );
#else
            fprintf( stderr, "pylupdate4 error: Cannot save '%s': %s\n",
                     fn.toLatin1().constData(), strerror(errno) );
#endif
        }
        ++t;
    }
}
开发者ID:CapB1ack,项目名称:PyQt4,代码行数:34,代码来源:main.cpp

示例7: on_treeView_clicked

void CPropBrowserWidget::on_treeView_clicked(const QModelIndex &index)
{
	QDir d;
	QString filePath;
	std::string stdFilePath;

	if(!m_model->isDir(index))
	{
		filePath = m_model->filePath(index);
		filePath = d.relativeFilePath(filePath);
		stdFilePath = filePath.toStdString();

		utils::changeExt(stdFilePath, "jpg");

		if(utils::fileExists(stdFilePath))
		{
			m_default = false;
			m_image.load(stdFilePath.c_str());
			ui->label->setPixmap(m_image);
		}
		else if(!m_default)
		{
			m_default = true;
			m_image.load(DEFAULT_PROPBROWSER_IMAGE_PATH);
			ui->label->setPixmap(m_image);
		}
	}
}
开发者ID:creepydragon,项目名称:revision1,代码行数:28,代码来源:CPropBrowserWidget.cpp

示例8: playListEntry

/*!
 \brief

 \param e
 \return QString
*/
QString PlayList::playListEntry(const M3uEntry& e) const {
    //obtain the filename to be used in the m3u playlist
    //not nescessary the same name as the original file
    //could be pointing to the location the original file is copied, if copied
    //could be relative or absolute
    //will also be different from originalFile if keepFolderStructure

    const QDir outPutPath(guiSettings->value("outPutPath") .toString());
    const QFileInfo file = e.originalFile();
    QString playListEntryName = file.absoluteFilePath();

    bool useCopyFilesToPath = guiSettings->value("useCopyFilesToPath").toBool();
    if (copyFiles_ && useCopyFilesToPath) {
        playListEntryName = copyFilesToDir_.absolutePath() + "/" + file.fileName();
        bool keepFolderStructure = guiSettings->value("keepFolderStructure").toBool();
        if (keepFolderStructure) {
            QStringList dirs = file.absolutePath().replace("\\", "/").split("/");
            QString root = dirs[0];            
            playListEntryName = file.absoluteFilePath().replace(root, copyFilesToDir_.absolutePath());

        }
    }

    if (relativePath_) {
        playListEntryName = outPutPath.relativeFilePath(playListEntryName);
    }

    return playListEntryName;
}
开发者ID:ivareske,项目名称:Playlist-Generator,代码行数:35,代码来源:PlayList.cpp

示例9: deploymentData

DeploymentData CMakeBuildConfiguration::deploymentData() const
{
    DeploymentData result;

    QDir sourceDir = target()->project()->projectDirectory().toString();
    QDir buildDir = buildDirectory().toString();

    QString deploymentPrefix;
    QString deploymentFilePath = sourceDir.filePath("QtCreatorDeployment.txt");

    bool hasDeploymentFile = QFileInfo::exists(deploymentFilePath);
    if (!hasDeploymentFile) {
        deploymentFilePath = buildDir.filePath("QtCreatorDeployment.txt");
        hasDeploymentFile = QFileInfo::exists(deploymentFilePath);
    }
    if (hasDeploymentFile) {
        deploymentPrefix = result.addFilesFromDeploymentFile(deploymentFilePath,
                                                             sourceDir.absolutePath());
    }

    for (const CMakeBuildTarget &ct : m_buildTargets) {
        if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType) {
            if (!ct.executable.isEmpty()
                    && !result.deployableForLocalFile(ct.executable.toString()).isValid()) {
                result.addFile(ct.executable.toString(),
                               deploymentPrefix + buildDir.relativeFilePath(ct.executable.toFileInfo().dir().path()),
                               DeployableFile::TypeExecutable);
            }
        }
    }

    return result;
}
开发者ID:sailfish-sdk,项目名称:sailfish-qtcreator,代码行数:33,代码来源:cmakebuildconfiguration.cpp

示例10: filesFromDarcs

QStringList KateProjectWorker::filesFromDarcs(const QDir &dir, bool recursive)
{
    QStringList files;

    const QString cmd = QStringLiteral("darcs");
    QString root;

    {
        QProcess darcs;
        darcs.setWorkingDirectory(dir.absolutePath());
        QStringList args;
        args << QStringLiteral("list") << QStringLiteral("repo");

        darcs.start(cmd, args);

        if (!darcs.waitForStarted() || !darcs.waitForFinished())
            return files;

        auto str = QString::fromLocal8Bit(darcs.readAllStandardOutput());
        QRegularExpression exp(QStringLiteral("Root: ([^\\n\\r]*)"));
        auto match = exp.match(str);

        if(!match.hasMatch())
            return files;

        root = match.captured(1);
    }

    QStringList relFiles;
    {
        QProcess darcs;
        QStringList args;
        darcs.setWorkingDirectory(dir.absolutePath());
        args << QStringLiteral("list") << QStringLiteral("files")
             << QStringLiteral("--no-directories") << QStringLiteral("--pending");

        darcs.start(cmd, args);

        if(!darcs.waitForStarted() || !darcs.waitForFinished())
            return files;

        relFiles = QString::fromLocal8Bit(darcs.readAllStandardOutput())
            .split(QRegularExpression(QStringLiteral("[\n\r]")), QString::SkipEmptyParts);
    }

    for (const QString &relFile: relFiles) {
        const QString path = dir.relativeFilePath(root + QStringLiteral("/") + relFile);

        if ((!recursive && (relFile.indexOf(QStringLiteral("/")) != -1)) ||
            (recursive && (relFile.indexOf(QStringLiteral("..")) == 0))
        ) {
            continue;
        }

        files.append(dir.absoluteFilePath(path));
    }

    return files;
}
开发者ID:benpope82,项目名称:kate,代码行数:59,代码来源:kateprojectworker.cpp

示例11: toMap

QVariantMap BareMetalRunConfiguration::toMap() const
{
    QVariantMap map(RunConfiguration::toMap());
    const QDir dir = QDir(target()->project()->projectDirectory().toString());
    map.insert(QLatin1String(ProFileKey), dir.relativeFilePath(m_projectFilePath));
    map.insert(QLatin1String(WorkingDirectoryKey), m_workingDirectory);
    return map;
}
开发者ID:KeeganRen,项目名称:qt-creator,代码行数:8,代码来源:baremetalrunconfiguration.cpp

示例12: relativeFilePath

static QString relativeFilePath(const QDir &dir,
                                const QString &fileName)
{
    // Likely a reference to a resource file
    if (fileName.startsWith(QLatin1Char(':')))
        return fileName;

    return dir.relativeFilePath(fileName);
}
开发者ID:jaman1020,项目名称:tiled,代码行数:9,代码来源:mapwriter.cpp

示例13: targetFile

Utils::FileName QmlProject::targetFile(const Utils::FileName &sourceFile,
                                       const Target *target) const
{
    const QDir sourceDir(m_projectItem ? m_projectItem->sourceDirectory()
                                       : canonicalProjectDir().toString());
    const QDir targetDir(targetDirectory(target).toString());
    const QString relative = sourceDir.relativeFilePath(sourceFile.toString());
    return Utils::FileName::fromString(QDir::cleanPath(targetDir.absoluteFilePath(relative)));
}
开发者ID:kai66673,项目名称:qt-creator,代码行数:9,代码来源:qmlproject.cpp

示例14: toMap

QVariantMap DesktopQmakeRunConfiguration::toMap() const
{
    const QDir projectDir = QDir(target()->project()->projectDirectory().toString());
    QVariantMap map(RunConfiguration::toMap());
    map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath.toString()));
    map.insert(QLatin1String(USE_DYLD_IMAGE_SUFFIX_KEY), m_isUsingDyldImageSuffix);
    map.insert(QLatin1String(USE_LIBRARY_SEARCH_PATH), m_isUsingLibrarySearchPath);
    return map;
}
开发者ID:DuinoDu,项目名称:qt-creator,代码行数:9,代码来源:desktopqmakerunconfiguration.cpp

示例15: projectDirRelativeToBuildDir

/////////////////////
// Helper Function
/////////////////////
static QString projectDirRelativeToBuildDir(BuildConfiguration *bc) {
    const QDir buildDir(bc->buildDirectory().toString());
    QString projDirToBuildDir = buildDir.relativeFilePath(
                bc->target()->project()->projectDirectory().toString());
    if (projDirToBuildDir.isEmpty())
        return QLatin1String("./");
    if (!projDirToBuildDir.endsWith(QLatin1Char('/')))
        projDirToBuildDir.append(QLatin1Char('/'));
    return projDirToBuildDir;
}
开发者ID:DuinoDu,项目名称:qt-creator,代码行数:13,代码来源:configurestep.cpp


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