Results 1 to 8 of 8

Thread: Printing Copyright Cicle C from QString

  1. #1
    Join Date
    Jan 2006
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Printing Copyright Cicle C from QString

    I'm trying to print the copyright circle C ( © ) into an output file (company requirement). I declare the first part of the copyright notice in a #define

    Qt Code:
    1. #define COPYRIGHT_PREFIX "\xA9 Copyright"
    2. #define COPYRIGHT_SUFFIX "Company Name. All Rights Reseved."
    To copy to clipboard, switch view to plain text mode 

    I then put it into a QString along with the year and then output it to a QDomDoc in the form of a QDomComment.

    Qt Code:
    1. QDomComment copyrightComment;
    2. QDate copyrightDate = QDate::currentDate( );
    3. QString copyrightString;
    4.  
    5. copyrightString.sprintf( "%s%d%s", COPYRIGHT_PREFIX, copyrightDate.year( ), COPYRIGHT_SUFFIX );
    6.  
    7. /* I created the document earlier */
    8. copyrightComment = outDoc.createComment( copyrightString );
    To copy to clipboard, switch view to plain text mode 

    When the comment in the document gets output to a file, I don't get the ©, but just get two question marks printed out ( ?? ). Is there something that I'm forgetting to do? Do I have to make use of one of the QString functions (I've tried .ascii( ) )?

    Any help is appreciated.
    The end of time is reached around the year 8000, by which time we expect Qt to be obsolete.

    -Note in QDate documentation. It's nice that Qt has been able to predict when the world will end.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing Copyright Cicle C from QString

    What encoding do you use for that XML file?

  3. #3
    Join Date
    Jan 2006
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing Copyright Cicle C from QString

    Quote Originally Posted by jacek
    What encoding do you use for that XML file?
    Not quite sure what you mean. I should have mentioned that when I'm done adding elements to the document I output it as a string.

    Qt Code:
    1. QString xmlString = outDoc.toString( );
    To copy to clipboard, switch view to plain text mode 

    After that, I open a file and send the string to the file.
    The end of time is reached around the year 8000, by which time we expect Qt to be obsolete.

    -Note in QDate documentation. It's nice that Qt has been able to predict when the world will end.

  4. #4
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing Copyright Cicle C from QString

    Just a thought
    Qt Code:
    1. #define COPYRIGHT_PREFIX 0xA9
    2. ...
    3. copyrightString.sprintf( "%c Copyright %d%s",
    4. COPYRIGHT_PREFIX,
    5. copyrightDate.year( ),
    6. COPYRIGHT_SUFFIX );
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing Copyright Cicle C from QString

    Quote Originally Posted by jakamph
    Not quite sure what you mean. I should have mentioned that when I'm done adding elements to the document I output it as a string.
    [...]
    After that, I open a file and send the string to the file.
    "\xA9" will mean different things depending on the encoding. For example in ISO 8859-1 and ISO 8859-2 it looks like this: "Š".

    IMO you should save this file using one of Unicode encodings, for example UTF-8.

  6. #6
    Join Date
    Jan 2006
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing Copyright Cicle C from QString

    Quote Originally Posted by yop
    Just a thought
    Qt Code:
    1. #define COPYRIGHT_PREFIX 0xA9
    2. ...
    3. copyrightString.sprintf( "%c Copyright %d%s",
    4. COPYRIGHT_PREFIX,
    5. copyrightDate.year( ),
    6. COPYRIGHT_SUFFIX );
    To copy to clipboard, switch view to plain text mode 
    This worked in this case. Thanks to yop and jacek for the help.
    The end of time is reached around the year 8000, by which time we expect Qt to be obsolete.

    -Note in QDate documentation. It's nice that Qt has been able to predict when the world will end.

  7. #7
    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: Printing Copyright Cicle C from QString

    You could just use "©". It is a sgml entity for the copyright sign. No matter the encoding, it'll get displayed right. Just make sure that "&" character doesn't get encoded as &

  8. #8
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing Copyright Cicle C from QString

    Quote Originally Posted by jacek
    "\xA9" will mean different things depending on the encoding. For example in ISO 8859-1 and ISO 8859-2 it looks like this: "Å ".

    IMO you should save this file using one of Unicode encodings, for example UTF-8.
    Encodings AFAIK are needed when you try something like QString foo("whatever"); foo.toAscii(); etc. In utf8 the copyright sign is indeed 0xA9 and luckily since QString is used utf8 is the "selected" encoding. But you are more than right that when playing around with strings you must always keep encoding differences in mind. (This was an easy one though as ?? in a string almost always mean wrong utf8 characters )
    Quote Originally Posted by wysota
    You could just use "©".
    Do you have a list with things like that? The first time I used xml it took me ages to find out how to use '&'
    Last edited by yop; 13th February 2006 at 23:07.

Similar Threads

  1. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 17:26
  2. Printing a Qstring
    By harakiri in forum Newbie
    Replies: 6
    Last Post: 24th June 2007, 13:52
  3. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 18:59

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.