Results 1 to 4 of 4

Thread: String Comparision

  1. #1
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default String Comparision

    I want whenever if (while ()) comes it will print Checking condition for If Statement and whenever while (if ()) comes it will print Checking condition for While Statement. I tried this code:

    if(cursor.block().text().contains("while",Qt::Case Insensitive)&& cursor.block().text().contains("(",Qt::CaseInsensi tive))
    {
    ui->label->setText("Checking condition for While Statement");

    }
    if(cursor.block().text().contains("if",Qt::CaseIns ensitive)&&cursor.block().text().contains("(",Qt:: CaseInsensitive))
    {
    ui->label->setText("Checking condition for If Statement");
    }

    when i entered only if () and only while () then it gives Checking condition for If Statement and Checking condition for While Statement respectively. But when i entered if (while ()) and while (if ()), it gives Checking condition for If Statement in both the cases.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: String Comparision

    Quote Originally Posted by parulkalra14 View Post
    when i entered only if () and only while () then it gives Checking condition for If Statement and Checking condition for While Statement respectively. But when i entered if (while ()) and while (if ()), it gives Checking condition for If Statement in both the cases.
    Not sure what your problem is, that is exactly what your code is supposed to do. I evalutes the first condition, finds it to be true and sets the label's text. Then it evaluates the second condition, also finds it to be true and sets the label's text to a different text.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: String Comparision

    I want when i entered while ( if () ) then label text will set to Checking condition for While Statement but instead of Checking condition for While Statement, Checking condition for If Statement appears in label text.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: String Comparision

    Both conditions are true for the given input, so it is quite clear that the last one will be displayed. Switch the order of both conditional blocks or change second one to "else if...".

  5. The following user says thank you to stampede for this useful post:

    parulkalra14 (29th January 2014)

Similar Threads

  1. Parenthesis Comparision with Enter key Event
    By parulkalra14 in forum Qt Programming
    Replies: 2
    Last Post: 22nd January 2014, 10:39
  2. QString comparision with some different char
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 18th May 2013, 22:26
  3. How to avoid type comparision using polymorphism
    By dancas2 in forum General Programming
    Replies: 8
    Last Post: 8th May 2012, 20:56
  4. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  5. Int to String - manipulating string
    By mickey in forum General Programming
    Replies: 6
    Last Post: 5th November 2007, 20:11

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.