Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] Any Chance to get result of QFileDialog::getOpenFileName

    General and Desktop
    3
    4
    2104
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      curator last edited by

      Hi again,

      In my GUI, I ask the user for Text and Filepaths. I perform der Text input by

      @
      QString p_Result = QInputDialog::getText(this, tr("Enter Something"),tr("Something"),QLineEdit::Normal,QString::fromUtf8(tmp.c_str()),&p_State);
      if(!p_State)return;
      @
      In the second line, i skip further computation is the user "aborted" his input rather than pressing ok.
      So far, so god.

      But if I ask the user to input a Filepath:

      @
      static QString getOpenFileName(QWidget *parent = 0,
      const QString &caption = QString(),
      const QString &dir = QString(),
      const QString &filter = QString(),
      QString *selectedFilter = 0,
      Options options = 0);
      @

      there is no such output parameter bool *ok like in

      @
      static QString getText(QWidget *parent, const QString &title, const QString &label,
      QLineEdit::EchoMode echo = QLineEdit::Normal,
      const QString &text = QString(), bool *ok = 0, Qt::WindowFlags flags = 0);
      @

      How do I check, wheather the user pressed ok oder abort? Checking the QString against QString("") only seems to be a workaround.

      kind regards,
      curator

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        [quote author="curator" date="1366105772"]
        How do I check, wheather the user pressed ok oder abort? Checking the QString against QString("") only seems to be a workaround.[/quote]
        Why do you think this is a "workaround"?! The dialog only has 2 results: Either the user selected a path or he didn't. Which is indicated by an empty string.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          The getOpenFileName documentation states that if the user canceled, the string returned is null. So the proper way to check is using QString::isNull();

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 0
          • C
            curator last edited by

            Thank you very much.

            I was just wondering, if there is a more common usage.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post