[Qt-interest] [SOLVED] Re: Problems with `password dialog' (Detailed)

Aaron Lewis aaron.lewis1989 at gmail.com
Thu Mar 11 11:50:41 CET 2010


Yeah , it's cool with SIGNAL and SLOTS ;-)

Thanks Tibor.

Tibor Kiss wrote:
> Well, there are plenty of ways to do it, you can share the pointers to
> the password/username, or other methods. Here is one, I prefer to do,
> see the example below, you send the information back to the mainwindow
> via signal.
>
> // the password dialog
> class pass : public QDialog
> {
>     Q_OBJECT
> public:
>     pass (QWidget *parent = 0);
> signals:
>     void gotpassword(QString, QString);    // we will use this signal
> ...
> };
>
> pass::pass (QWidget *parent) : QDialog (parent)
> {
> ... just set up the UI for the dialog
> }
>
> void pass::on_okbutton_clicked ()
> {
>     ... check the password, if OK ...
>     emit gotpassword(username, password);    // fire the signal, the
> info is inside...
>     close();
> }
>
>
> In the mainwindow, when you create the dialog:
>
> ...
> pass *dialog = new pass (this);
> connect (dialog, SIGNAL (gotpossword(QString, QString)), this, SLOT
> (login(QString, QString)));
> dialog->exec();
> ...
>
> And ofcourse, you need a slot in the mainwindow for login
>
> void mainwindow::login(QString username, QString password)
> {
>     .... do with the username and password whatever you would like ....
> }
>
> I hope this helps...
> Tibor
>
> 2010/3/11 Aaron Lewis <aaron.lewis1989 at gmail.com
> <mailto:aaron.lewis1989 at gmail.com>>
>
>     Here's some more information:
>
>      Actually i'm writing a Mysql Front End , when user triggered the
>     `Connection' action ,
>
>      I'd like to show up a new Dialog , and let user type in informations
>     (kinds of username , passwd , hostname e.g)
>
>      When she clicked on some button (e.g Yes) , dialog is closed ,  data
>     format is checked (isValid)
>       then these information are transfered back to MainWindow (class
>     qsqlcc)
>
>      Now i'll be able to make connection between my program and mysql
>     server
>
>     That's what i'm doing ..
>
>     Appreciate your help ;-)
>
>     Tibor Kiss wrote:
>     > Well, the information is a bit short to analyse your problem.
>     >
>     > First, some typo, I think if you have
>     > qgetpass::qgetpass (QWidget *parent , QString *username , QString
>     > *passwd , QString *host)
>     >
>     > then here, you should have a parent:
>     > qgetpass *passDialog = new qgetpass(this,
>     &_username,&_passwd,&_host);
>     >
>     > So, regarding the password problem, I do it like this, it's very
>     > simple and usefull:
>     >
>     > class pass : public QDialog
>     > {
>     >     Q_OBJECT
>     > public:
>     >     pass (QWidget *parent = 0);
>     > ...
>     > nothing extra here, some buttons, etc
>     > ...
>     > };
>     >
>     > pass::pass (QWidget *parent) : QDialog (parent)
>     > {
>     > ... just set up the UI for the dialog
>     > }
>     >
>     > void pass::on_okbutton_clicked ()
>     > {
>     >     ... check the password ...
>     >     done(id);    // return ID of the user
>     > }
>     >
>     > void pass::on_cancel_clicked ()
>     > {
>     >     done(0);
>     > }
>     >
>     > And finally in the mainwindow:
>     >
>     > ...
>     > pass *dialog = new pass (this);
>     > int id = dialog->exec();
>     > if (id == 0) return;    // we don't have a positive
>     authentication...
>     > ...
>     >
>     > If you happen to make the password dialog more than once in your
>     > program, you should think about it's destruction, because
>     otherwise it
>     > will go out of the memory only when you close your mainwindow.
>     You can
>     > check QPointer types for the safe delete methods.
>     >
>     > 2010/3/10 Aaron Lewis <aaron.lewis1989 at gmail.com
>     <mailto:aaron.lewis1989 at gmail.com>
>     > <mailto:aaron.lewis1989 at gmail.com
>     <mailto:aaron.lewis1989 at gmail.com>>>
>     >
>     >     Hi,
>     >        I have a main window, and i want to dynamically create a
>     Dialog to
>     >     get informations ( kinds of user-name , password e.g)
>     >
>     >        I have two classes , qsqlcc and qgetpass.
>     >
>     >        I tried some sample code:
>     >
>     >        I) In class getpass , i tried to take advantage of construct
>     >     function , tried to pass pointers to it:
>     >        qgetpass::qgetpass (QWidget *parent , QString *username ,
>     QString
>     >     *passwd , QString *host)
>     >        ..
>     >
>     >        II) In MainWindow , in some function
>     >
>     >        qgetpass *passDialog = new
>     qgetpass(&_username,&_passwd,&_host);
>     >
>     >        I then will got empty strings . I thought i should use
>     >     connections ,
>     >     but i've got no ideas..
>     >
>     >        Any ideas will appreciate .
>     >
>     >     --
>     >     Best Regards,
>     >     Aaron Lewis - PGP: 0x4A6D32A0
>     >     FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
>     >     irc: A4r0n on freenode
>     >
>     >     _______________________________________________
>     >     Qt-interest mailing list
>     >     Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>     <mailto:Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>>
>     >     http://lists.trolltech.com/mailman/listinfo/qt-interest
>     >
>     >
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > Qt-interest mailing list
>     > Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>     > http://lists.trolltech.com/mailman/listinfo/qt-interest
>     >
>
>
>     --
>     Best Regards,
>     Aaron Lewis - PGP: 0x4A6D32A0
>     FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
>     irc: A4r0n on freenode
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   
[

-- 
Best Regards,
Aaron Lewis - PGP: 0x4A6D32A0
FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
irc: A4r0n on freenode




More information about the Qt-interest-old mailing list