Results 1 to 3 of 3

Thread: Proper use of an InputDialog box - capture CANCEL click

  1. #1
    Join Date
    Apr 2017
    Posts
    55
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Proper use of an InputDialog box - capture CANCEL click

    I have the following function that is a SIMPLE password input dialog.

    It works except that I cannot capture and process the CANCEL button click.
    When CANCEL is clicked I want the dialog box to close without doing anything.
    I have the cancel variable for the button click return but cannot get it done.

    Here's the function
    Qt Code:
    1. int class::display_password_dialog()
    2. {
    3. QString retarg;
    4. bool cancel;
    5.  
    6. do
    7. {
    8. retarg = QInputDialot::gettext(0,"Password Entry", "Type Password, Press Ok: ",QLineEdit::Normal, "***", &cancel);
    9. std::cout <<"user entered"<< retarg.toStdString()<<std::endl;
    10. if(cancel)
    11. {
    12. std::cout<<"Cancel pressed"<<std::endl;
    13. return EXIT_FAILURE;
    14. }
    15. } while (retarg != "'");
    16. return EXIT_SUCCESS;
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by emp1953; 9th November 2017 at 21:41. Reason: typo

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Proper use of an InputDialog box - capture CANCEL click

    Read the docs again:

    [static] QString QInputDialog::getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString &text = QString(), bool *ok = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags(), Qt::InputMethodHints inputMethodHints = Qt::ImhNone)

    Static convenience function to get a string from the user.

    title is the text which is displayed in the title bar of the dialog. label is the text which is shown to the user (it should say what should be entered). text is the default text which is placed in the line edit. mode is the echo mode the line edit will use. inputMethodHints is the input method hints that will be used in the edit widget if an input method is active.

    If ok is nonnull *ok will be set to true if the user pressed OK and to false if the user pressed Cancel. The dialog's parent is parent. The dialog will be modal and uses the specified widget flags.
    Your logic in line 10 is exactly backward.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2017
    Posts
    55
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Proper use of an InputDialog box - capture CANCEL click

    I read that part of the docs several times and still implemented the logic backwards. Thank you for the quick solution.

Similar Threads

  1. Replies: 0
    Last Post: 24th May 2016, 12:53
  2. Replies: 1
    Last Post: 3rd April 2016, 00:10
  3. Proper handling "Cancel" click for QWizard
    By Splinter in forum Qt Programming
    Replies: 4
    Last Post: 17th September 2012, 14:34
  4. Replies: 2
    Last Post: 16th July 2012, 12:40
  5. Replies: 3
    Last Post: 5th July 2009, 17:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.