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


C++ QFileDialog::setDirectoryUrl方法代码示例

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


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

示例1: pickFiles

void Transcribe::pickFiles() {
  QFileDialog dlg;

  // Unfortunately, Android doesn't really work with the concept of files,
  // they are abstracted away. Since it would require a major effort to make
  // this work in the Android way, we'll just try to make the best of it.
#ifdef Q_OS_ANDROID
    // First see if we have storage permissions. We fail here if we don't have
    // them and let the callback to the request popup call this method again.
    if (!StoragePerm::instance()->tryPermission(std::bind(&Transcribe::pickFiles, this))) return;

    // Make the QFileDialog a bit better by maximizing it.
    dlg.setWindowState(Qt::WindowMaximized);
    dlg.setViewMode(QFileDialog::List);

    // Add the root and the internal memory location to the paths to choose
    // from. There are no real standard paths for this, let's hope Qt knows
    // what to do.
    QUrl home_url = QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first());
    dlg.setDirectoryUrl(home_url);
    QList<QUrl> urls;
    urls << QUrl::fromLocalFile("/");
    urls << home_url;
    dlg.setSidebarUrls(urls);
#endif

  // Let the user pick an audio file
  dlg.setWindowTitle(tr("Open an audio file"));
  dlg.setNameFilter(tr("Audio files (*.wav *.mp3 *.aac *.amr *.aiff *.flac *.ogg *.wma, *.opus)"));
  dlg.setFileMode(QFileDialog::ExistingFile);
  dlg.setAcceptMode(QFileDialog::AcceptOpen);
  if (dlg.exec() == QDialog::Rejected || dlg.selectedFiles().count() != 1) {
    return;
  }

  m_restore_pos = 0;
  openAudioFile(dlg.selectedFiles().at(0));

#ifdef Q_OS_ANDROID
  QString audio_path = dlg.selectedFiles().at(0);
  QString text_path;

  // Check if the audio file is in our history
  if (!m_history.textFileForAudio(audio_path, text_path)) {
    // If not, create a new file in the app private folder based on the audio
    // file name. If a text file with the name already exists, append a number
    // to it.
    QString base_name = QFileInfo(audio_path).baseName();
    QDir home = QDir(QStandardPaths::writableLocation((QStandardPaths::AppDataLocation)));
    text_path = home.filePath(base_name + ".txt");
    short counter = 1;
    while (QFile::exists(text_path)) {
      text_path = home.filePath(QString("%1_%2.txt").arg(base_name).arg(counter, 2, 10, QChar('0')));
      counter++;
    }
  }

  openTextFile(text_path);
#else
  // Recycle the file dialog to let the user pick a text file for the
  // transcript. As a file suggestion, we base a txt file on the current audio
  // file.
  dlg.setWindowTitle(tr("Pick a text file for the transcript"));
  dlg.setNameFilter(tr("Text files (*.txt)"));
  dlg.setFileMode(QFileDialog::AnyFile);
  dlg.setAcceptMode(QFileDialog::AcceptSave);
  dlg.setOption(QFileDialog::DontConfirmOverwrite, true);
  dlg.setLabelText(QFileDialog::Accept, tr("Open/Create"));
  QFileInfo info(dlg.selectedFiles().at(0));
  dlg.setDirectory(info.absolutePath());
  dlg.selectFile(info.baseName() + ".txt");
  if (dlg.exec() == QDialog::Rejected || dlg.selectedFiles().count() != 1) {
    return;
  }

  openTextFile(dlg.selectedFiles().at(0));
#endif

  // saveHistory() is called when the audio file has finished loading, but we
  // need do it here as well because openTextFile() might return after the audio
  // file has finished loading. The joys of concurrency ...
  saveHistory();
}
开发者ID:p-edelman,项目名称:Transcribe,代码行数:83,代码来源:transcribe.cpp


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