• 6212阅读
  • 0回复

[提问]用QPrinter导出PDF格式的文件,程序界面乱码的问题 [复制链接]

上一主题 下一主题
离线longle323
 

只看楼主 倒序阅读 楼主  发表于: 2008-07-29
— 本帖被 XChinux 从 Qt基础编程 移动到本区(2013-04-01) —
我仿照QT的DEMO里面的例子写了个导出PDF文件
#ifndef QT_NO_PRINTER
if (!fileName.isEmpty())
{
if (QFileInfo(fileName).suffix().isEmpty())
fileName.append(".pdf");
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
QFile file(fileName);
if (!file.open(QFile::WriteOnly))
{
emit Savedone(false);
return;
}
QTextDocument *test;
test = new QTextDocument(this);
QFont Font;
Font.setFamily("宋体");
test->setDefaultFont(Font);
QString a,b;
a = Summary(checkerpt.reports[0],1);
if(rpt)
{

test->setHtml(a+b);
}
else
{

test->setHtml(a+b);//a,b是字符串,是个标准的HTML页
}
test->print(&printer);
emit Savedone(true);
}
else
{
emit Savedone(false);
return;
}
#endif
}
在导出完的时候经常界面里的文字会变乱码,我指界面,不是PDF文件里的字,偶尔会中断,由于文件比较大,我这个函数是写在一个线程里面去导出文件的,防止调用导出函数的界面死掉,有没有了解问题的症结所在的给点提示,很头疼啊。。。
快速回复
限100 字节
 
上一个 下一个