Results 1 to 4 of 4

Thread: small symbian software development Using C++ and qt GUI

  1. #1
    Join Date
    Apr 2012
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default small symbian software development Using C++ and qt GUI

    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:n_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.............

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: small symbian software development Using C++ and qt GUI

    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.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: small symbian software development Using C++ and qt GUI

    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):
    Qt Code:
    1. //probably this is not working
    2. if((name==s1[i].username) && (pass=s1[i].pass)) //it most likely should be (pass == s1[i].pass)
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: small symbian software development Using C++ and qt GUI

    Nice catch, missed it myself. All my compilers issue a warning when you do this.

Similar Threads

  1. Qt Software Development at Technicolor
    By Markus in forum Jobs
    Replies: 2
    Last Post: 22nd March 2012, 21:20
  2. Qt Software Development Job
    By Markus in forum Jobs
    Replies: 1
    Last Post: 1st November 2011, 00:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.