Results 1 to 7 of 7

Thread: QString problem?

  1. #1
    Join Date
    Mar 2010
    Location
    Alipurduar, India
    Posts
    8
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question QString problem?

    QString userentry = ui->lineEdit->text();.

    Now i need to loop through each character of the string and find the a matching charecter "A"

    for(i=0;i<=20;i++)
    {
    if( userentry[i] == 'A' )
    .............

    }

    I am getting error

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QString problem?

    What error do you get? use userentry.length() instead of fixed integer. See also QString::indexOf().

  3. The following user says thank you to Lykurg for this useful post:

    askbapi (31st March 2010)

  4. #3
    Join Date
    Mar 2010
    Location
    Alipurduar, India
    Posts
    8
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QString problem?

    how can I get each character of Qsrting?

    Native C++ style:
    ---------------------------------------------------
    char userenter[30]; int i;

    userenter[]="god is great";

    for(i=0; i<= 29; i++)
    {
    cout << userenter[i] << endl;

    }

    how to do it with QString?

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QString problem?

    Qt Code:
    1. QString str = "fooBar";
    2. for (int i = 0; i < str.length(); ++i)
    3. qWarning() << str.at(i); // or str[i]
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to Lykurg for this useful post:

    askbapi (31st March 2010)

  7. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QString problem?

    You can also use QString::indexOf , cant you

  8. The following user says thank you to aamer4yu for this useful post:

    askbapi (31st March 2010)

  9. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QString problem?

    Quote Originally Posted by askbapi View Post
    Native C++ style:
    ---------------------------------------------------
    char userenter[30]; int i;

    userenter[]="god is great";

    for(i=0; i<= 29; i++)
    {
    cout << userenter[i] << endl;

    }

    how to do it with QString?
    Qt Code:
    1. QString userenter;
    2.  
    3. userenter ="god is great";
    4.  
    5. for(int i=0; i<= userenter.size(); i++)
    6. {
    7. cout << userenter[i] << endl;
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    By the way, your code is incorrect.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    askbapi (31st March 2010)

  11. #7
    Join Date
    Mar 2010
    Location
    Alipurduar, India
    Posts
    8
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QString problem?

    Thanks for your valuable reply!

    It is clear.

Similar Threads

  1. QString problem...
    By Nefastious in forum Newbie
    Replies: 17
    Last Post: 29th September 2009, 16:29
  2. problem in QString
    By wagmare in forum Qt Programming
    Replies: 4
    Last Post: 23rd December 2008, 13:28
  3. QString problem?
    By raphaelf in forum Newbie
    Replies: 7
    Last Post: 24th June 2008, 09:12
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. QString problem
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2006, 19:10

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
  •  
Qt is a trademark of The Qt Company.