Results 1 to 3 of 3

Thread: Difference between ' & "

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Difference between ' & "

    I have a basic program:

    Qt Code:
    1. char chTest;
    2. chTest = 'a';
    3. qDebug() << chTest;
    To copy to clipboard, switch view to plain text mode 

    However if I use "a", it spits out an error at me - 47: error: invalid conversion from 'const char*' to 'char'

    What does that error mean? And why does it occur?

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

    Default Re: Difference between ' & "

    Qt Code:
    1. char c = 'a'; // one character
    2. char *str = "a"; // string literal
    To copy to clipboard, switch view to plain text mode 
    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.


  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Difference between ' & "

    However if I use "a", it spits out an error at me - 47: error: invalid conversion from 'const char*' to 'char'
    Error says it, keeping the const qualifier aside in the error ouput, looks like you are converting from 'char' to 'char*'.

    'char' and 'char*' are different types and cannot be assigned / implicitly converted.

    When you bring in const back in discussion. One can convert 'const char*' to 'char*', but other way 'char*' to 'const char*', is not implicitly possible.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 1
    Last Post: 10th October 2012, 08:46
  2. Difference and Importance of ".a" and ".lib"
    By iamDAMON in forum General Programming
    Replies: 2
    Last Post: 1st October 2012, 13:50
  3. Replies: 3
    Last Post: 15th February 2010, 17:27
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.