0
点赞
收藏
分享

微信扫一扫

以下简单示例演示了如何在任何Qt应用程序中轻松集成和使用NCReport


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最新试用版

报表解决方案NCReport更新至2.23.3版本|附下载

工程档案

QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport

TARGET = MySimpleDemo
TEMPLATE = app
SOURCES += main.cpp

win32:CONFIG(release, debug|release) : LIBS += -LPWD/…/ncreport/lib/ -lNCReportDebug2

INCLUDEPATH += $$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正版授权的朋友欢迎咨询【慧都】在线客服


举报

相关推荐

0 条评论