[Qt-interest] How to close QMainWindow and open login dialog
Israel Brewster
israel at frontierflying.com
Fri Aug 7 18:53:26 CEST 2009
So am I understanding you correctly in that validating the login is
not done within the LoginDialog itself, but in the function it is
called from? So when the user hits login, that signal is connected to
a slot in the calling function that runs the loginvalidate() function,
which then decides what to do? I'm not sure I quite understand your
logic flow here. However, for what it is worth, I have a program with
a login/logout functionality as well, which I accomplish as the
following:
1) the main function shows the loginWindow (inherited from QDialog)
and starts the event loop
2) the user enters their username/password and hits the login button
3) the login button clicked() signal calls a verify function (lets
call it loginvalidate()) of the loginWindow() class.
4) this function validates the login (yep, it's against a mysql
database just like yours), and either opens a QMainWindow (if valid)
or displays an error (if invalid). So in psuedocode, you'd have
something like the following:
void loginWindow::loginvalidate(QString user, QString password)
{
bool valid=checkLogin(user,password) //check user and password
against database- implemented however.
if(valid)
{
MyQMainWindow * window=new MyQMainWindow; //create the
QMainWindow to show
window->show(); //show the main window
close(); //close the loginWindow
}
else
{
//do whatever you want here, such as display error, exit
application, etc.
}
}
5) then when the user chooses logout in the main window, I simply run
code like the following:
void MyQMainWindow::logout()
{
loginWindow * loginWindow=new loginWindow; //create new login window
loginWindow.show(); //show the new window
close(); //close the QMainWindow
}
Since the loginWindow class is completely self-contained, doing all
the validation within itself, you don't have to worry about connecting
a signal in the LoginDialog to QMainWindow. You just have to make sure
that LoginDialog has the proper includes to be able to create a
QMainWindow, and that QMainWindow has the proper includes to be able
to create a LoginDialog. But as I said, I'm not quite sure I fully
understand your problem, so perhaps this won't help you much.
-----------------------------------------------
Israel Brewster
Computer Support Technician II
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 397 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090807/7a5a3671/attachment.bin
-------------- next part --------------
On Aug 7, 2009, at 6:25 AM, Aditya Sharma wrote:
> The problem goes like this,
> In an application I am building, I have one instance of LoginDialog
> inherited from QDialog. This takes username and password, if match
> is not found in the mysql database, the loginvalidate() returns 0.
> Return type of loginValidate of LoginDialog is used to determine
> whether or not to exit the program from the event loop in the main
> function. If match is found, program flow is as usual, opens the
> main window.
>
> Now here comes the problem. I have logout button in the QMainWindow
> inherited class. When it is clicked, private slot, logout() is
> called, in the logout() slot, i can write close() to close the
> current instance of QMainWindow, but how can I show to login dialog,
> Well, making a new object newlogin will help but still, slots in the
> LoginDialog won't call QMainWindow. What can I do.
>
> THank you in advance.
>
>
> Advance. _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list