PDA

View Full Version : Printing Copyright Cicle C from QString



jakamph
13th February 2006, 22:03
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


#define COPYRIGHT_PREFIX "\xA9 Copyright"
#define COPYRIGHT_SUFFIX "Company Name. All Rights Reseved."

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


QDomComment copyrightComment;
QDate copyrightDate = QDate::currentDate( );
QString copyrightString;

copyrightString.sprintf( "%s%d%s", COPYRIGHT_PREFIX, copyrightDate.year( ), COPYRIGHT_SUFFIX );

/* I created the document earlier */
copyrightComment = outDoc.createComment( copyrightString );

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.

jacek
13th February 2006, 22:04
What encoding do you use for that XML file?

jakamph
13th February 2006, 22:14
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.


QString xmlString = outDoc.toString( );

After that, I open a file and send the string to the file.

yop
13th February 2006, 22:32
Just a thought


#define COPYRIGHT_PREFIX 0xA9
...
copyrightString.sprintf( "%c Copyright %d%s",
COPYRIGHT_PREFIX,
copyrightDate.year( ),
COPYRIGHT_SUFFIX );

jacek
13th February 2006, 22:46
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.

jakamph
13th February 2006, 22:47
Just a thought


#define COPYRIGHT_PREFIX 0xA9
...
copyrightString.sprintf( "%c Copyright %d%s",
COPYRIGHT_PREFIX,
copyrightDate.year( ),
COPYRIGHT_SUFFIX );


This worked in this case. Thanks to yop and jacek for the help.

wysota
13th February 2006, 23:04
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 & :)

yop
13th February 2006, 23:04
"\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 ;))

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 '&'