PDA

View Full Version : how to mask the lineEdit text with asterisks for password entry?



prasad1001
5th February 2014, 09:59
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...

wagmare
5th February 2014, 10:13
go through this example
http://qt-project.org/doc/qt-4.8/widgets-lineedits.html
especially the echo mode ..

prasad1001
5th February 2014, 10:37
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...

anda_skoa
5th February 2014, 11:04
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,
_

wagmare
5th February 2014, 11:05
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 ..

prasad1001
5th February 2014, 11:29
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 10014
as shown in above fig..
and i also tested by setting password option in designer also...
please help me...

prasad1001
6th February 2014, 04:20
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...

ChrisW67
6th February 2014, 04:40
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:


#include <QApplication>
#include <QLineEdit>
#include <QDebug>

int main(int argc, char **argv) {
QApplication app(argc, argv);
QLineEdit l;
l.setEchoMode(QLineEdit::Password);
l.show();
qDebug() << "Should see dots" << QString(5, QChar(0x25CF)) << QString(5, QChar(0x2022));
return app.exec();
}

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 (http://www.charbase.com/25cf-unicode-black-circle) or U+2022 (http://www.charbase.com/2022-unicode-bullet) because these are selected in preference to '*' which is the fallback option.

prasad1001
7th February 2014, 11:41
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..

ChrisW67
7th February 2014, 13:39
Do you see dots the code prints in the debug output?

prasad1001
10th February 2014, 05:39
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..

anda_skoa
10th February 2014, 09:13
Have you tried a different widget style? Maybe the one you are currently using is just displaying spaces?

Cheers,
_

prasad1001
10th February 2014, 13:13
Thanks for the quick reply...
I was tried with a new dialog and created every thing new..but same result.....

Thanks in advance..

anda_skoa
10th February 2014, 13:51
So the next thing would be to try my suggestion from comment #12

Cheers,
_

ChrisW67
10th February 2014, 19:54
What anda_skoa means is, compile your simple test code and run it like this:


./program -style windows

(Assuming you are running on Linux)

prasad1001
11th February 2014, 05:36
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..

ChrisW67
11th February 2014, 05:48
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...

prasad1001
11th February 2014, 06:37
Thanks for the quick reply,
I am using...
Qt version 4.8.1
OS---Ubuntu 12.04 LTS (32 bit)
Desktop Environment--Unity

ChrisW67
11th February 2014, 22:19
Right, so does it still fail with the latest Qt 4.8.5?

wysota
12th February 2014, 07:32
I would try setting a different font for the widget.