以下简单示例演示了如何在任何Qt应用程序中轻松集成和使用NCReport。这些代码与Qt4.6-Qt5.8兼容。项目文件设置基于Qt .pro文件语法。
NCReport是一个基于Qt跨平台应用程序和UI框架,使用C++编写的强大、快速、多平台、容易使用的报告引擎库、报表生成器、报表设计器、 报表记录器、报表工具、报表解决方案。如果你在寻找Qt报表引擎、Qt报表工具、Qt报表库等等,那么NCReport就是你的最佳选择。并且NCReport兼容Qt5和Qt4。
该系统由两部分组成:报告呈现库和报告设计器GUI应用程序。报表引擎可以单独使用和实现。报告模板文件格式为XML格式,可以从文件,字符串或sql数据库中加载模板。该系统能够生成各种类型的输出,例如直接打印机,内部预览窗口,postscript,PDF,SVG,图像,文本,HTML。报表设计器使创建报表XML定义变得非常容易。
NCReport现已更新至2.23.4版本,修复了一些小的bug,感兴趣的朋友欢迎下载体验哦~
NCReport最新试用版
工程档案
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupportTARGET = MySimpleDemoTEMPLATE = appSOURCES += main.cppwin32:CONFIG(release, debug|release) : LIBS += -L$$PWD/../ncreport/lib/ -lNCReport2else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../ncreport/lib/ -lNCReportDebug2INCLUDEPATH += $$PWD/../ncreport/includes
将报告运行到预览窗口1
int main(int argc, char *argv[]){ QApplication a(argc, argv); NCReport *report = new NCReport(); report->setReportSource( NCReportSource::File ); // set report source type report->setReportFile("myreport.ncr"); //set the report filename fullpath or relative to dir report->runReportToPreview(); // run to preview output // error handling if( report->hasError()) { QMessageBox msgBox; msgBox.setText(QObject::tr("Report error: ") + report->lastErrorMsg()); msgBox.exec(); } else { // show preview NCReportPreviewWindow *pv = new NCReportPreviewWindow(); // create preview window pv->setOutput( (NCReportPreviewOutput*)report->output() ); // add output to the window pv->setReport(report); pv->setWindowModality(Qt::ApplicationModal ); // set modality pv->setAttribute( Qt::WA_DeleteOnClose ); // set attrib pv->exec(); // run like modal dialog } delete report;}
将报告运行到预览窗口2
int main(int argc, char *argv[]){ QApplication a(argc, argv); NCReport *report = new NCReport(); report->setReportFile("myreport.ncr"); //set the report filename fullpath or relative to dir report->runReportToShowPreview(); // run and show to preview output // error handling if( report->hasError()) { QMessageBox msgBox; msgBox.setText(QObject::tr("Report error: ") + report->lastErrorMsg()); msgBox.exec(); } delete report;}
将报告生成为PDF
int main(int argc, char *argv[]){ QApplication a(argc, argv); NCReport *report = new NCReport(); report->setReportFile("myreport.ncr"); //set the report filename fullpath or relative to dir report->runReportToPDF("c:/temp/myreportoutput.pdf") // error handling if( report->hasError()) { QMessageBox msgBox; msgBox.setText(QObject::tr("Report error: ") + report->lastErrorMsg()); msgBox.exec(); } delete report;}
**想要了解或购买NCReport正版授权的朋友欢迎咨询在线客服
标签:
来源:慧都
声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!