本文整理汇总了C++中QFileDialog::selectedFiles方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileDialog::selectedFiles方法的具体用法?C++ QFileDialog::selectedFiles怎么用?C++ QFileDialog::selectedFiles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileDialog
的用法示例。
在下文中一共展示了QFileDialog::selectedFiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_actionLoad_triggered
void MainWindow::on_actionLoad_triggered()
{
QFileDialog dg;
dg.setToolTip(tr("Open file with gamers names"));
dg.setLabelText(QFileDialog::Accept,tr("Open"));
dg.setLabelText(QFileDialog::LookIn,tr("Open"));
dg.setWindowTitle("Open file with gamers names");
if ( QDialog::Rejected == dg.exec())
{
return;
}
QFile file(dg.selectedFiles().at(0)) ;
if(!file.open(QIODevice::ReadOnly))
qWarning("failed to open file %s",dg.selectedFiles().at(0).toStdString().c_str());
else
{
#if DEBUG
qWarning("successed to open file %s",dg.selectedFiles().at(0).toStdString().c_str());
#endif
}
QString str;
QByteArray arr = file.readAll();
str = str.fromLocal8Bit(arr );
md->set_gamers( str.split(","));
file.close();
}
示例2: OpenWAVFile
void MainWindow::OpenWAVFile()
{
QFileDialog *g = new QFileDialog(this);
#if QT_VERSION==0x040806 || defined(Q_OS_UNIX)
g->setNameFilter("Audio Files (*.wav | *.mp3)");
#else
g->setNameFilter("Audio Files (*.wav;*.mp3)");
#endif
#if QT_VERSION>=0x050000 && !defined(Q_OS_UNIX)
g->setDirectory(lastdirR);
#endif
if(g->exec())
{
ui->listWidget->clear();
f = fopen(g->selectedFiles().at(0).toLocal8Bit().constData(),"rb");
fread(&format,1,44,f);
fclose(f);
ui->locut->setMaximum(format.SampleRate/2);
ui->hicut->setMaximum(format.SampleRate/2);
ui->locutslider->setMaximum(format.SampleRate/2);
ui->hicutslider->setMaximum(format.SampleRate/2);
filename = g->selectedFiles().at(0);
QFileInfo info(g->selectedFiles().at(0));
lastdirR = info.absolutePath();
ui->actionApply_Effect->setEnabled(true);
ui->pushButton->setEnabled(true);
}
}
示例3: assert
void Dialog::on_button_1_clicked()
{
QFileDialog d;
//enum ViewMode { Detail, List };
d.setViewMode(QFileDialog::Detail);
//enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
d.setFileMode(QFileDialog::ExistingFiles);
//enum AcceptMode { AcceptOpen, AcceptSave };
d.setAcceptDrops(QFileDialog::AcceptOpen);
//enum Option { ShowDirsOnly, DontResolveSymlinks, DontConfirmOverwrite, DontUseSheet, DontUseNativeDialog, ReadOnly, HideNameFilterDetails }
d.setOptions(QFileDialog::ReadOnly);
d.exec();
std::stringstream s;
if (d.result() == QDialog::Accepted)
{
s << "Number of files selected: " << d.selectedFiles().size() << '\n';
const auto v = d.selectedFiles();
for (auto f: v) s << f.toStdString() << '\n';
}
else
{
assert(d.result() == QDialog::Rejected);
s << "Dialog closed with cancel or close\n";
}
ui->text_1->setPlainText(s.str().c_str());
}
示例4: saveAsDialog
bool FileSystem::saveAsDialog()
{
QFileDialog dialog;
dialog.setMimeTypeFilters(Config::supportedSaveMimeTypes());
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.selectFile(getCurrentAbsoluteFileName());
dialog.setDirectory(getCurrentAbsoluteFileName());
dialog.selectMimeTypeFilter("image/jpeg");
bool success;
if(dialog.exec())
{
QImage img;
if(SaveConfirmation::imageWasChanged(getCurrentAbsoluteFileName()))
{
img = SaveConfirmation::getChagedImage(getCurrentAbsoluteFileName());
success = img.save(dialog.selectedFiles().first());
if(success)
SaveConfirmation::deleteImage(getCurrentAbsoluteFileName());
}
else
{
img.load(getCurrentAbsoluteFileName());
success = img.save(dialog.selectedFiles().first());
}
}
return success;
}
示例5: choosePath
void MainWindow::choosePath() {
QFileDialog dirDialog;
dirDialog.setFileMode(QFileDialog::DirectoryOnly);
dirDialog.setDirectory(ui->lineEdit_3->text());
if(dirDialog.exec()) {
if(!dirDialog.selectedFiles().isEmpty())
ui->lineEdit_3->setText(dirDialog.selectedFiles().at(0));
}
}
示例6: browseButtonClicked
void MainWindow::browseButtonClicked()
{
QFileDialog tmp;
if (tmp.exec())
{
if (tmp.selectedFiles().size() > 0)
{
ui.logFileLineEdit->setText(tmp.selectedFiles()[0]);
}
}
}
示例7: selectAssetDir
void ZoneViewerWindow::selectAssetDir()
{
QFileDialog fd;
fd.setFileMode(QFileDialog::Directory);
fd.setDirectory(m_scene->assetPath());
fd.setWindowTitle("Select an asset directory");
// OpenGL rendering interferes wtih QFileDialog
m_viewport->setAnimation(false);
if((fd.exec() == QDialog::Accepted) && (fd.selectedFiles().count() > 0))
m_scene->setAssetPath(fd.selectedFiles().value(0));
m_viewport->setAnimation(true);
}
示例8: on_actionSave_triggered
void MainWindow::on_actionSave_triggered()
{
#ifdef full_gui_functionality
QFileDialog dialog;
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setAcceptMode(QFileDialog::AcceptMode::AcceptSave);
if(dialog.exec()) {
ofstream f(dialog.selectedFiles()[0].toStdString());
f << ui->plainTextEdit->toPlainText().toStdString();
old_adress = dialog.selectedFiles()[0].toStdString();
}
#endif
}
示例9: loadDialogAccepted
void PresetManager::loadDialogAccepted()
{
QFileDialog *dialog = qobject_cast<QFileDialog*>(sender());
if (!dialog || (dialog->selectedFiles().size() == 0))
{
return;
}
m_presetFile.setFile(dialog->selectedFiles().first());
dialog->deleteLater();
// read presets
readPresetFile();
}
示例10: openFileUI
std::fstream* openFileUI(QWidget* parent, bool save, QString filter, QString* name = 0) {
QFileDialog dialog (parent);
dialog.setFileMode(save ? QFileDialog::FileMode::AnyFile : QFileDialog::FileMode::ExistingFile);
dialog.setNameFilter(filter);
dialog.setAcceptMode(save ? QFileDialog::AcceptMode::AcceptSave : QFileDialog::AcceptMode::AcceptOpen);
if (dialog.exec()) {
if (name != nullptr)
*name = dialog.selectedFiles().front();
std::fstream* stream = new std::fstream();
stream->open(dialog.selectedFiles().front().toStdString(), save ? std::ios_base::out : std::ios_base::in);
return stream;
} else {
return nullptr;
}
}
示例11: on_actionLoad_triggered
void MainWindow::on_actionLoad_triggered()
{
#ifdef full_gui_functionality
QFileDialog dialog;
dialog.setFileMode(QFileDialog::AnyFile);
if(dialog.exec()) {
ifstream f(dialog.selectedFiles()[0].toStdString());
stringstream ff;
ff << f.rdbuf();
auto qtxt = QString::fromStdString(ff.str());
ui->plainTextEdit->setPlainText(qtxt);
old_adress = dialog.selectedFiles()[0].toStdString();
}
#endif
}
示例12: ChooseFile
QString MainWindow::ChooseFile(QString filename){
QFileDialog *fd = new QFileDialog(this,tr("Choose Dataset File"), "/Users/Zhangjun/Documents/C++Work/BPNN/data","" );
fd->setFileMode(QFileDialog::ExistingFile);
fd->setViewMode(QFileDialog::Detail);
QStringList filters;
filters << "*.csv" << "*.dat" << "*.txt" << "*.*";
fd->setNameFilters(filters);
QStringList fileNamesList;
if(fd->exec()) // ok
{
fileNamesList = fd->selectedFiles();
QString fileName = fileNamesList.at(0).toLocal8Bit().constData();
return fileName;
}else{
return filename;
}
}
示例13: SelectDeformationField
void QmitkBSplineRegistrationView::SelectDeformationField()
{
// SELECT FOLDER DIALOG
QFileDialog* w = new QFileDialog( this, "Select Deformation Field" );
w->setFileMode( QFileDialog::ExistingFiles );
w->setFilter( "Images (*.mhd)" );
w->setDirectory("G:\\home\\vanbrugg\\testimages\\deformable");
// RETRIEVE SELECTION
if ( w->exec() != QDialog::Accepted )
{
return;
cout << "Failed to load" << endl;
}
QStringList filenames = w->selectedFiles();
QStringList::Iterator it = filenames.begin();
if( it != filenames.end() ) {
std::string filename = ( *it ).toStdString();
++it;
QString qStr = QString( filename.c_str() );
m_Controls.m_DeformationField->setText(qStr);
}
}
示例14: on_action_Export_Scenes_triggered
void MainWindow::on_action_Export_Scenes_triggered()
{
QFileDialog fileDialog;
fileDialog.setWindowTitle(tr("Export"));
// Set the dialog for saving files, sets the dialog button to "Save"
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
// Set the dialog to display the Desktop folder as default location
fileDialog.setDirectory(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
// Set the dialog to return the file name wheather the file exists or not
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setNameFilter(tr("XML Data File") + " (*.xml)");
bool wasFileSelected = fileDialog.exec();
QString filePath;
if (wasFileSelected) {
filePath = fileDialog.selectedFiles().at(0);
qDebug() << "Exporting file: " + filePath;
try {
_sceneDataFile->exportTo(filePath);
}
catch (SceneDataFileException& exception)
{
QMessageBox::critical(this,
tr("ERROR: File Export Failed"),
exception.getMessage());
return; // If export failed
}
}
else
{
return; // If no file was selected
}
} // on_action_Export_Scenes_triggered()
示例15: onChangeDataDirectory
void MainWindow::onChangeDataDirectory()
{
QFileDialog dlg;
dlg.setAcceptMode(QFileDialog::AcceptOpen);
dlg.setFileMode(QFileDialog::Directory);
dlg.setOption(QFileDialog::ShowDirsOnly, true);
if (dlg.exec()) {
QString path = dlg.selectedFiles().at(0);
DatabaseDlg dbdlg(QDir(path), this);
if (dbdlg.exec()) {
Parser *p = new Parser(path, m_output);
p->restrictYears(dbdlg.getSelectedYears());
activateWindow();
raise();
p->moveToThread(&m_thread);
connect(&m_thread, SIGNAL(finished()), p, SLOT(deleteLater()));
connect(p, SIGNAL(finished()), this, SLOT(onParseFinished()));
connect(this, SIGNAL(parse()), p, SLOT(parse()));
m_thread.start();
emit parse();
}
}
}