Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Any Chance to get result of QFileDialog::getOpenFileName

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.4k Views
  • 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 Offline
    C Offline
    curator
    wrote on last edited by
    #1

    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
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      [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
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        0
        • C Offline
          C Offline
          curator
          wrote on last edited by
          #4

          Thank you very much.

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved