Results 1 to 4 of 4

Thread: how to compare a Qstring with a constant char*

  1. #1
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default how to compare a Qstring with a constant char*

    I have to compare the text of a buton with a const , say for example "Set Homograph"...qstrcmp is showing error:
    if(qstrcmp(localCalibrateControlsObj->setHomographyButton->text(),"Set Homography")==0)
    ERROR:cannot convert QString to const cha *....

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: how to compare a Qstring with a constant char*

    You can use QString(const char* str) to convert it to a QString

  3. #3
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to compare a Qstring with a constant char*

    while QString has implicit constructor you can compare them with == operator
    Qt Code:
    1. if ( localCalibrateControlsObj->setHomographyButton->text() == "Set Homography" ) ...
    To copy to clipboard, switch view to plain text mode 

    and if you want to compare with qstrcmp you should get a const char pointer to QString data like this
    Qt Code:
    1. if ( qstrcmp( localCalibrateControlsObj->setHomographyButton->text().toAscii().constData(),"Set Homography")==0) ...
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to borisbn for this useful post:

    qt_user (10th August 2010)

  5. #4
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default Re: how to compare a Qstring with a constant char*

    thanx............thanx a lot

Similar Threads

  1. How to Compare two QString in the form of QDateTime ?
    By George Neil in forum Qt Programming
    Replies: 4
    Last Post: 1st March 2010, 06:57
  2. QString to char *
    By barrygp in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2009, 20:02
  3. Replies: 4
    Last Post: 31st January 2008, 20:44
  4. QString to Char
    By kenny_isles in forum Newbie
    Replies: 1
    Last Post: 23rd February 2007, 09:51
  5. Compare QString alphabet position
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2006, 16:50

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.