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



  • 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


  • Moderators

    [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.


  • Lifetime Qt Champion

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



  • Thank you very much.

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.