Login window
-
Ah, oke, learned something new there. Nice, but still it is bad pratice to create a new object and don't keep the pointer at hand ;-)
-
Hi all,
I tried to resolve the problem by writing a code example: (Connecting to a PostgreSQL data base)create a login window
create a data base connection
show the login window
enter the username and the passwd (repeat until the login is accepted or the operation is canceled)
login succeeded ==> create and show the main window
@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);LoginWindow Lwindow;
/* accepted = 1; rejected = 0; */
int result;
bool pass = false;
int response;QSqlDatabase Dbase;
Dbase = QSqlDatabase::addDatabase("QPSQL");
Dbase.setHostName("localhost");
Dbase.setDatabaseName("database_name");while(!pass)
{
Lwindow.exec();
result = Lwindow.result();
if(result == 0)
{
pass = true;
Lwindow.done(0);
return 0;
}
else
{
QString user = Lwindow.getUser();
QString password = Lwindow.getPassword();
Dbase.setUserName(user);
Dbase.setPassword(password);
pass = Dbase.open();/* if(m_dbase.lastError().isValid()) */
if(!pass)
{
response = QMessageBox::critical(NULL, "Data Base Access Problem",Dbase.lastError().text(),QMessageBox::Cancel|QMessageBox::Retry);
if(response == QMessageBox::Cancel)
{
pass = true;
return 0;
}
}
}
}MainWindow Mwindow(Dbase);
Mwindow.setGeometry(100,100,500,600);
Mwindow.show();
return app.exec();
}@
-
[quote author="issam" date="1348049464"]Hi all,
I tried to resolve the problem by writing a code example like this :
[/quote]Nice. And what was the result of that attempt? Did it work? If it did: congrats. If it did not: what failed exactly? What did you expect?
-
If you ask me it should work just fine. Maybe a bit of comments to add, but looks fine to me. Did it work??
-
It works well ! ;)
"download...":http://www.iissam.com/dbases/index.html
-
[quote author="issam" date="1348128467"]
It works well ! ;)"download...":http://www.iissam.com/dbases/index.html
[/quote]Thank you....
-
Dear issam,
Where is the Lwindow definition? Do you separate into lwindow.cpp and lwindow.h?
Thanks in advance.