|
how to display the chinese character? |
Posted by qt version support UTF8? on Jun-22-2011 13:30 |
|
I am use the ubuntu 11.04 version, amd64 arch.
UTF8 codec
but when I use the chardirector qt version ,can not display the right code, only display the "?"
I am wonder that the chardirector support the UTF8? |
Re: how to display the chinese character? |
Posted by Peter Kwan on Jun-22-2011 18:07 |
|
Hi,
If you see the "?" character, the most likely reason is because either your text editor or compiler does not understand your text in the source code, so it changes your text to "?".
If your text is in the source code, the compiler would need to compile the code first to machine language first. To do this, the compiler must understand your code. If your code contains a text string "abcd", but the compiler cannot understand it, it may change the characters to "?".
Even if the compiler can understand the text, if the compiler thinks it is impossible to compile the text into machine language (eg. it may be configured to produce ASCII text string in the machine language output), it may change the characters to "?".
Another possibility is that your code is using the default fonts (eg, arial.ttf), which does not have Chinese characters. However, if this is the cause of the problem, usually the characters will become a "dot" or a "square" (not a "?").
Because in Linux, there is no standard location for fonts, so in ChartDirector, it would only look for fonts in the "fonts" subdirectory under the directory that contains "libchartdir.so".
I have attached an example based on the QT sample code "helloworld.cpp". It adds a Chinese title to the chart. I used the wide char syntax L"xxx", so that the compiler knows the text will be compiled to unicode in machine language. It then use the QString.toUtf8 function to convert it to UTF8 (to make sure it is really UTF8). To compile and run the attached "helloworld.app", simply copy it to the QT helloworld sample project, replacing the existing "helloworld.cpp".
Note that the attached code uses the "mingliu.ttc" font. If you are using different font, please change the code to the Chinese font you are using. Make sure the font is in the "fonts" subdirectory under the under the directory that contains "libchartdir.so".
If the above still cannot solve the problem, would you mind to include a screen show me the output of the "helloworld.cpp" code?
Hope this can help.
Regards
Peter Kwan
helloworld.cpp |
---|
#include <QApplication>
#include "qchartviewer.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QChartViewer viewer;
//
// Draw Chart and set to QChartViewer
//
// The data for the bar chart
double data[] = {85, 156, 179.5, 211, 123};
// The labels for the bar chart
const char *labels[] = {"Mon", "Tue", "Wed", "Thu", "Fri"};
// Create a XYChart object of size 250 x 250 pixels
XYChart *c = new XYChart(250, 250);
c->setDefaultFonts("mingliu.ttc", "mingliu.ttc Bold");
c->addTitle(QString::fromWCharArray(L"漢語").toUtf8());
// Set the plotarea at (30, 20) and of size 200 x 200 pixels
c->setPlotArea(30, 20, 200, 200);
// Add a bar chart layer using the given data
c->addBarLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])));
// Set the labels on the x axis.
c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0])));
// Output the chart
viewer.setChart(c);
// Include tool tip for the chart
viewer.setImageMap(
c->getHTMLImageMap("", "", "title='{xLabel}: US${value}K'"));
// In this sample project, we do not need to chart object any more, so we
// delete it now.
delete c;
//
// Show the viewer
//
viewer.show();
return app.exec();
}
|
| |
|