PDA

View Full Version : small symbian software development Using C++ and qt GUI



ritesh
13th April 2012, 04:06
hi i am developing a small Qt gui-application problem here is that i am not able to compare two std strings. In Qt how can i compare two strings.. here is that button code snippet...

in the below code i am simply creating a login page please suggest any alternatives as soon as possible....

void MainWindow::on_pushButton_clicked()
{
stud s1[10];
int flag=0;

string name=ui->lineEdit->text().toStdString();
string pass=ui->lineEdit_2->text().toStdString();
if(pass=="")
{
QMessageBox q1;
q1.setText("PASSWORD CANNOT BE BLANK");
q1.exec();
}
else if(name=="")
{
QMessageBox q1;
q1.setText("NAME AND PASSWORD CANNOT BE BLANK");
q1.exec();
flag=0;
}
//opening file and reading data
ifstream fib;
fib.open("stud.txt");
for(int j=0; j<4; j++)
{
fib>>s1[j].user_name>>s1[j].pass;

}
fib.close();

for(int i=0; i<4; i++)
{
//probably this is not working
if((name==s1[i].username) && (pass=s1[i].pass))
{
flag=1;
}
else
{
flag=0;
}
}

if(flag==1)
{
QMessageBox q1;
q1.setText("VALID-USER");
q1.exec();
MainWindow1 *w=new MainWindow1();
w->show();
this->close();
}
else
{
QMessageBox q1;
q1.setText("INVALID-USER");
q1.exec();
ui->lineEdit->clear();
ui->lineEdit_2->clear();
}
}
thanks.............:D

ChrisW67
13th April 2012, 05:45
You have chosen to use the standard library string so you can use std::string::empty() and std::string::operator==(). This has, of course, nothing at all to do with Qt or Symbian.

If you were using the QString class you could use QString::isEmpty() and QString::operator==(). You'll notice the similarity to the std::string methods.

I suspect your problem, whatever it is exactly, is elsewhere.

Zlatomir
13th April 2012, 13:06
This piece of code might be a typo if you didn't copy/paste the code, or it could be the problem: you have = (assignment) instead of == (equality):

//probably this is not working
if((name==s1[i].username) && (pass=s1[i].pass)) //it most likely should be (pass == s1[i].pass)

ChrisW67
13th April 2012, 21:30
Nice catch, missed it myself. All my compilers issue a warning when you do this.