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


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

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


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

示例1: 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());
}
开发者ID:RLED,项目名称:ProjectRichelBilderbeek,代码行数:32,代码来源:dialog.cpp

示例2: actionOpen

void MainWindow::actionOpen()
{
	QString filePath;
	QFileDialog* fileDialog = new QFileDialog(this,
						  tr("Select File to open"),
						  m_pathImport,
						  tr("All Compatible (*.wzm *.pie *.obj);;"
						     "WZM models (*.wzm);;"
						     "PIE models (*.pie);;"
						     "OBJ files (*.obj)"));
	fileDialog->setFileMode(QFileDialog::ExistingFile);
	fileDialog->exec();

	if (fileDialog->result() == QDialog::Accepted)
	{
		filePath = fileDialog->selectedFiles().first();

		// refresh import working dir
		m_pathImport = fileDialog->directory().absolutePath();
		m_settings->setValue(WMIT_SETTINGS_IMPORTVAL, m_pathImport);

		PrependFileToRecentList(filePath);
	}

	delete fileDialog;
	fileDialog = nullptr;

	if (!filePath.isEmpty())
	{
		openFile(filePath);
		// else popup on fail?
	}
}
开发者ID:iNoDlite,项目名称:WMIT,代码行数:33,代码来源:MainWindow.cpp

示例3: main

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);

  QFileDialog d;

  //enum ViewMode { Detail, List };
  d.setViewMode(QFileDialog::Detail);

  //enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
  d.setFileMode(QFileDialog::AnyFile);

  //enum AcceptMode { AcceptOpen, AcceptSave };
  d.setAcceptDrops(QFileDialog::AcceptSave);

  //enum Option { ShowDirsOnly, DontResolveSymlinks, DontConfirmOverwrite, DontUseSheet, DontUseNativeDialog, ReadOnly, HideNameFilterDetails }
  //Without QFileDialog::DontUseNativeDialog there will not be an edit box to supply
  //a filename, under Lubuntu 13.04 (raring)
  d.setOptions(QFileDialog::DontUseNativeDialog);

  d.setWindowTitle("Save"); //Otherwise it states 'Open'

  d.exec();

  if (d.result() == QDialog::Accepted)
  {
    std::cout << "Number of files selected: " << d.selectedFiles().size() << '\n';
    const auto v = d.selectedFiles();
    for (auto s: v) std::cout << s.toStdString() << '\n';
  }
  else
  {
    assert(d.result() == QDialog::Rejected);
    std::cout << "Dialog closed with cancel or close\n";
  }
}
开发者ID:RLED,项目名称:ProjectRichelBilderbeek,代码行数:36,代码来源:main.cpp

示例4: actionAppendModel

void MainWindow::actionAppendModel()
{
	QString filePath;
	QFileDialog* fileDialog = new QFileDialog(this,
						  tr("Select file to append"),
						  m_pathImport,
						  tr("All Compatible (*.wzm *.pie *.obj);;"
						     "WZM models (*.wzm);;"
						     "PIE models (*.pie);;"
						     "OBJ files (*.obj)"));
	fileDialog->setFileMode(QFileDialog::ExistingFile);
	fileDialog->exec();

	if (fileDialog->result() == QDialog::Accepted)
	{
		filePath = fileDialog->selectedFiles().first();
	}
	delete fileDialog;
	fileDialog = nullptr;

	if (!filePath.isEmpty())
	{
		ModelInfo newinfo;
		WZM newmodel;

		if (loadModel(filePath, newmodel, newinfo))
		{
			for (int i = 0; i < newmodel.meshes(); ++i)
			{
				m_model.addMesh(newmodel.getMesh(i));
			}

			doAfterModelWasLoaded();
		}
	}
}
开发者ID:iNoDlite,项目名称:WMIT,代码行数:36,代码来源:MainWindow.cpp

示例5: actionSaveAs

void MainWindow::actionSaveAs()
{
	ModelInfo tmpModelinfo(m_modelinfo);

	QStringList filters;
	filters << "PIE3 models (*.pie)" << "PIE2 models (*.pie)" << "WZM models (*.wzm)" << "OBJ files (*.obj)";

	QList<wmit_filetype_t> types;
	types << WMIT_FT_PIE << WMIT_FT_PIE2 << WMIT_FT_WZM << WMIT_FT_OBJ;

	QFileDialog* fDialog = new QFileDialog();

	fDialog->setFileMode(QFileDialog::AnyFile);
	fDialog->setAcceptMode(QFileDialog::AcceptSave);
	fDialog->setNameFilters(filters);
	fDialog->setWindowTitle(tr("Choose output file"));
	fDialog->setDirectory(m_pathExport);
	fDialog->exec();

	if (fDialog->result() != QDialog::Accepted)
	{
		return;
	}

	if (!filters.contains(fDialog->selectedNameFilter()))
	{
		return;
	}

	tmpModelinfo.m_save_type = types[filters.indexOf(fDialog->selectedNameFilter())];

	// refresh export working dir
	m_pathExport = fDialog->directory().absolutePath();
	m_settings->setValue(WMIT_SETTINGS_EXPORTVAL, m_pathExport);

	QFileInfo finfo(fDialog->selectedFiles().first());
	tmpModelinfo.m_saveAsFile = finfo.filePath();

	QPointer<ExportDialog> dlg;

	switch (tmpModelinfo.m_save_type)
	{
	case WMIT_FT_PIE:
	case WMIT_FT_PIE2:
		tmpModelinfo.defaultPieCapsIfNeeded();
		dlg = new PieExportDialog(tmpModelinfo.m_pieCaps, this);
		if (dlg->exec() == QDialog::Accepted)
		{
			tmpModelinfo.m_pieCaps = static_cast<PieExportDialog*>(dlg.data())->getCaps();
		}

		if (finfo.suffix().toLower() != "pie")
			tmpModelinfo.m_saveAsFile += ".pie";
		break;
	case WMIT_FT_OBJ:
		if (finfo.suffix().toLower() != "obj")
			tmpModelinfo.m_saveAsFile += ".obj";
		break;
	case WMIT_FT_WZM:
		if (finfo.suffix().toLower() != "wzm")
			tmpModelinfo.m_saveAsFile += ".wzm";
		break;
	}

	if (dlg && dlg->result() != QDialog::Accepted)
	{
		return;
	}

	m_modelinfo = tmpModelinfo;
	PrependFileToRecentList(m_modelinfo.m_saveAsFile);

	saveModel(m_model, m_modelinfo);
}
开发者ID:iNoDlite,项目名称:WMIT,代码行数:74,代码来源:MainWindow.cpp

示例6: getOpenFileNames

/* static */
QStringList QIFileDialog::getOpenFileNames (const QString &aStartWith,
                                            const QString &aFilters,
                                            QWidget       *aParent,
                                            const QString &aCaption,
                                            QString       *aSelectedFilter /* = 0 */,
                                            bool           aResolveSymlinks /* = true */,
                                            bool           aSingleFile /* = false */)
{
/* It seems, running QFileDialog in separate thread is NOT needed under windows any more: */
#if defined (VBOX_WS_WIN) && (QT_VERSION < 0x040403)

    /**
     *  QEvent class reimplementation to carry Win32 API native dialog's
     *  result folder information
     */
    class GetOpenFileNameEvent : public OpenNativeDialogEvent
    {
    public:

        enum { TypeId = QEvent::User + 3 };

        GetOpenFileNameEvent (const QString &aResult)
            : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
    };

    /**
     *  QThread class reimplementation to open Win32 API native file dialog
     */
    class Thread : public QThread
    {
    public:

        Thread (QWidget *aParent, QObject *aTarget,
                const QString &aStartWith, const QString &aFilters,
                const QString &aCaption) :
                mParent (aParent), mTarget (aTarget),
                mStartWith (aStartWith), mFilters (aFilters),
                mCaption (aCaption) {}

        virtual void run()
        {
            QString result;

            QString workDir;
            QString initSel;
            QFileInfo fi (mStartWith);

            if (fi.isDir())
                workDir = mStartWith;
            else
            {
                workDir = fi.absolutePath();
                initSel = fi.fileName();
            }

            workDir = QDir::toNativeSeparators (workDir);
            if (!workDir.endsWith ("\\"))
                workDir += "\\";

            QString title = mCaption.isNull() ? tr ("Select a file") : mCaption;

            QWidget *topParent = windowManager().realParentWindow(mParent ? mParent : windowManager().mainWindowShown());
            QString winFilters = winFilter (mFilters);
            AssertCompile (sizeof (TCHAR) == sizeof (QChar));
            TCHAR buf [1024];
            if (initSel.length() > 0 && initSel.length() < sizeof (buf))
                memcpy (buf, initSel.isNull() ? 0 : initSel.utf16(),
                        (initSel.length() + 1) * sizeof (TCHAR));
            else
                buf [0] = 0;

            OPENFILENAME ofn;
            memset (&ofn, 0, sizeof (OPENFILENAME));

            ofn.lStructSize = sizeof (OPENFILENAME);
            ofn.hwndOwner = topParent ? topParent->winId() : 0;
            ofn.lpstrFilter = (TCHAR *)(winFilters.isNull() ? 0 : winFilters.utf16());
            ofn.lpstrFile = buf;
            ofn.nMaxFile = sizeof (buf) - 1;
            ofn.lpstrInitialDir = (TCHAR *)(workDir.isNull() ? 0 : workDir.utf16());
            ofn.lpstrTitle = (TCHAR *)(title.isNull() ? 0 : title.utf16());
            ofn.Flags = (OFN_NOCHANGEDIR | OFN_HIDEREADONLY |
                          OFN_EXPLORER | OFN_ENABLEHOOK |
                          OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST);
            ofn.lpfnHook = OFNHookProc;

            if (GetOpenFileName (&ofn))
            {
                result = QString::fromUtf16 ((ushort *) ofn.lpstrFile);
            }

            // qt_win_eatMouseMove();
            MSG msg = {0, 0, 0, 0, 0, 0, 0};
            while (PeekMessage (&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE));
            if (msg.message == WM_MOUSEMOVE)
                PostMessage (msg.hwnd, msg.message, 0, msg.lParam);

            result = result.isEmpty() ? result : QFileInfo (result).absoluteFilePath();

//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:virtualbox,代码行数:101,代码来源:QIFileDialog.cpp

示例7: getExistingDirectory

/**
 *  Reimplementation of QFileDialog::getExistingDirectory() that removes some
 *  oddities and limitations.
 *
 *  On Win32, this function makes sure a native dialog is launched in
 *  another thread to avoid dialog visualization errors occurring due to
 *  multi-threaded COM apartment initialization on the main UI thread while
 *  the appropriate native dialog function expects a single-threaded one.
 *
 *  On all other platforms, this function is equivalent to
 *  QFileDialog::getExistingDirectory().
 */
QString QIFileDialog::getExistingDirectory (const QString &aDir,
                                            QWidget *aParent,
                                            const QString &aCaption,
                                            bool aDirOnly,
                                            bool aResolveSymlinks)
{
#if defined(VBOX_WS_WIN) && (QT_VERSION < 0x050000)

    /**
     *  QEvent class reimplementation to carry Win32 API
     *  native dialog's result folder information
     */
    class GetExistDirectoryEvent : public OpenNativeDialogEvent
    {
    public:

        enum { TypeId = QEvent::User + 1 };

        GetExistDirectoryEvent (const QString &aResult)
            : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
    };

    /**
     *  QThread class reimplementation to open Win32 API
     *  native folder's dialog
     */
    class Thread : public QThread
    {
    public:

        Thread (QWidget *aParent, QObject *aTarget,
                const QString &aDir, const QString &aCaption)
            : mParent (aParent), mTarget (aTarget), mDir (aDir), mCaption (aCaption) {}

        virtual void run()
        {
            QString result;

            QWidget *topParent = windowManager().realParentWindow(mParent ? mParent : windowManager().mainWindowShown());
            QString title = mCaption.isNull() ? tr ("Select a directory") : mCaption;

            TCHAR path [MAX_PATH];
            path [0] = 0;
            TCHAR initPath [MAX_PATH];
            initPath [0] = 0;

            BROWSEINFO bi;
            bi.hwndOwner = topParent ? topParent->winId() : 0;
            bi.pidlRoot = 0;
            bi.lpszTitle = (TCHAR*)(title.isNull() ? 0 : title.utf16());
            bi.pszDisplayName = initPath;
            bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_NEWDIALOGSTYLE;
            bi.lpfn = winGetExistDirCallbackProc;
            bi.lParam = uintptr_t(&mDir);

            LPITEMIDLIST itemIdList = SHBrowseForFolder (&bi);
            if (itemIdList)
            {
                SHGetPathFromIDList (itemIdList, path);
                IMalloc *pMalloc;
                if (SHGetMalloc (&pMalloc) != NOERROR)
                    result = QString::null;
                else
                {
                    pMalloc->Free (itemIdList);
                    pMalloc->Release();
                    result = QString::fromUtf16 ((ushort*)path);
                }
            }
            else
                result = QString::null;
            QApplication::postEvent (mTarget, new GetExistDirectoryEvent (result));
        }

    private:

        QWidget *mParent;
        QObject *mTarget;
        QString mDir;
        QString mCaption;
    };

    /* Local event loop to run while waiting for the result from another
     * thread */
    QEventLoop loop;

    QString dir = QDir::toNativeSeparators (aDir);
    LoopObject loopObject ((QEvent::Type) GetExistDirectoryEvent::TypeId, loop);
//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:virtualbox,代码行数:101,代码来源:QIFileDialog.cpp


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