Results 1 to 20 of 20

Thread: how to mask the lineEdit text with asterisks for password entry?

  1. #1
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default how to mask the lineEdit text with asterisks for password entry?

    Hello Qt Experts,

    i want to use my lineEdit for the login form ....so how do I make the QLineEdit widget mask the text in it with circles or asterisks for password entry and how i get the entered text to a Qstring?

    Thanks in Advance...

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    go through this example
    http://qt-project.org/doc/qt-4.8/widgets-lineedits.html
    especially the echo mode ..
    "Behind every great fortune lies a crime" - Balzac

  3. The following user says thank you to wagmare for this useful post:

    prasad1001 (5th February 2014)

  4. #3
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    Thanks for the quick reply...
    i have set the echoMode to 'password'. And now when i type the password it displays nothing...means only cursor is moving.
    Now how to replace those null characters to asterisks or hash symbols..

    Thanks in advance...

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    The password echo mode does that, but the actual visualization depends on the widget style.
    Try running your application with a different style if you don't like how the current one works.

    Cheers,
    _

  6. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    did u given the echo mode like this . it should work ..
    lineEdit->setEchoMode(QLineEdit::Password);
    in you code ..
    please post a minimal compactible code ..
    or follow as anda mentioned in earlier reply. change style ..
    "Behind every great fortune lies a crime" - Balzac

  7. #6
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    i have set the echoMode as stated by you...

    mainwindow.h
    private:
    Ui::MainWindow *ui;
    QLabel *labelPass;

    mainwindow.cpp
    linePass=ui->linePass;
    linePass->setEchoMode(QLineEdit::Password);

    but it getting a blank line edit even if i type in using password echo mode error.png
    as shown in above fig..
    and i also tested by setting password option in designer also...
    please help me...

  8. #7
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    i have set the echoMode as stated by you...

    mainwindow.h
    private:
    Ui::MainWindow *ui;
    QLabel *labelPass;
    mainwindow.cpp
    linePass=ui->linePass;
    linePass->setEchoMode(QLineEdit::Password);
    but it getting a blank line edit even if i type in using password echo mode Click image for larger version Name: error.png Views: 6 Size: 13.2 KB ID: 10014
    as shown in above fig..
    and i also tested by setting password option in designer also...
    please help me...

  9. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    Repeating yourself will not change the outcome. Doing something to try to help yourself might.

    Here is the complete, small, test case you could have written to confirm the behaviour:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLineEdit>
    3. #include <QDebug>
    4.  
    5. int main(int argc, char **argv) {
    6. QApplication app(argc, argv);
    7. l.setEchoMode(QLineEdit::Password);
    8. l.show();
    9. qDebug() << "Should see dots" << QString(5, QChar(0x25CF)) << QString(5, QChar(0x2022));
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Does it fail with this?

    If not then the problem in your program is external to the QLineEdit.
    Have you applied a style sheet? Is the text/foreground colour white?
    Does your font have a glyph for Unicode code points U+25CF or U+2022 because these are selected in preference to '*' which is the fallback option.
    Last edited by ChrisW67; 6th February 2014 at 05:47. Reason: updated contents

  10. The following user says thank you to ChrisW67 for this useful post:

    prasad1001 (7th February 2014)

  11. #9
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    Thanks for the reply....

    i was tested with ur code also sir..but i am gettting the same result with blank spaces..My Qt creator version is 2.6.1.
    and i was not used the stylesheet for the lineEdit..

    And i didn't get ur point about the font i.e.."Does your font have a glyph for Unicode code points U+25CF or U+2022"..

    Thank you in advance..

  12. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    Do you see dots the code prints in the debug output?

  13. #11
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    Sorry for the delay sir...
    yes it prints the dots in debug output..

    i was tried by changing the font styles also, but same problem i am getting..nothing displaying in the lineEdit...

    Thanks in advance..

  14. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    Have you tried a different widget style? Maybe the one you are currently using is just displaying spaces?

    Cheers,
    _

  15. #13
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    Thanks for the quick reply...
    I was tried with a new dialog and created every thing new..but same result.....

    Thanks in advance..

  16. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    So the next thing would be to try my suggestion from comment #12

    Cheers,
    _

  17. #15
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    What anda_skoa means is, compile your simple test code and run it like this:
    Qt Code:
    1. ./program -style windows
    To copy to clipboard, switch view to plain text mode 
    (Assuming you are running on Linux)

  18. #16
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    I was tried like that also..i.e. by running my application in terminal..
    $ ./password -style windows

    But the same thing is happening...is this the creator problem..My Qt creator version is 2.6.1.

    Thanks in advance..

  19. #17
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    It is irrelevant what version of Qt Creator you are using.

    It is important what version of Qt libraries you are using, what operating system you are on, what desktop environment is involved, what compiler you are
    using...

  20. #18
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    Thanks for the quick reply,
    I am using...
    Qt version 4.8.1
    OS---Ubuntu 12.04 LTS (32 bit)
    Desktop Environment--Unity

  21. #19
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    Right, so does it still fail with the latest Qt 4.8.5?

  22. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    I would try setting a different font for the widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 7
    Last Post: 5th February 2014, 12:20
  2. how to get the text from a LineEdit using QT??
    By Soumya Somasekhar Ram in forum Qt Programming
    Replies: 11
    Last Post: 11th September 2013, 14:43
  3. reading the latest entry text from QplaintextEdit
    By PHANI in forum Qt Programming
    Replies: 3
    Last Post: 6th February 2012, 12:30
  4. QLineEdit shadow text disappear on first entry
    By dentharg in forum Qt Programming
    Replies: 1
    Last Post: 6th July 2008, 18:40

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.