如何在任何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 += -L$$PWD/../ncreport/lib/ -lNCReport2
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../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正版授權的朋友歡迎諮詢慧都在線客服

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章