我正在尝试将QtRPT实现为我的qt程序的报告生成器。 我很难找到QtRPT选择的任何教程。以下方法来自西班牙公司的教程:
这是我初始化变量的地方:
while(q.next()){
check_no = q.value(0).toString();
alobs_no=q.value(1).toString();
payee=q.value(2).toString();
bank_account_no = q.value(10).toString();
bank_name = q.value(9).toString();
cancelled = q.value(7).toInt();
amount = q.value(5).toDouble();
date = q.value(26).toString();
date_breakdown = date.split("/");
month = date_breakdown.at(0).toInt();
day = date_breakdown.at(1).toInt();
year = date_breakdown.at(2).toInt();
date_of_check.setDate(year,month,day);
//total = q.value(0).toString();
//ui->checksEntry_tbl->data
certifier = q.value(11).toString();
certifier_pos = q.value(17).toString();
deliverer = q.value(13).toString();
deliverer_pos = q.value(19).toString();
approver = q.value(12).toString();
approver_pos = q.value(18).toString();
//total_amount = q2.value(3).toDouble();
}
q.finish();
q2.finish();
这是我将程序连接到QtDesigner创建的xml的部分,以及问题的根源:
//QTRPT writing phase
QtRPT *report = new QtRPT(this);
report->loadReport(":/acic_report.xml");
report->recordCount.append(rowtablecount);
connect(report, &QtRPT::setValue, [&](const int recNo,
const QString paramName, QVariant ¶mValue,
const int reportPage) {
(void) reportPage;
if(paramName == "dateprep"){
paramValue = date_prepared;
}
if(paramName == "acic"){
paramValue = acic_no;
}
if(paramName == "fund"){
paramValue = fund_type;
}
if(paramName == "bankaccnt"){
paramValue = bank_account_no;
}
if(paramName == "bankname"){
paramValue = bank_name;
}
if(paramName == "ALOBS No."){
paramValue = alobs_no;
}
if(paramName == "Check No."){
paramValue = check_no;
}
if(paramName == "Payee"){
paramValue = payee;
}
if(paramName == "Check Date"){
paramValue = date_of_check;
}
if(paramName == "Amount"){
paramValue = amount;
}
if(paramName == "Total"){
paramValue = total_amount;
}
if(paramName == "totalwords"){
paramValue = pesoword;
}
if(paramName == "ccname"){
paramValue = certifier;
}
if(paramName == "ccpos"){
paramValue = certifier_pos;
}
if(paramName == "appname"){
paramValue = approver;
}
if(paramName == "apppos"){
paramValue = approver_pos;
}
if(paramName == "delivname"){
paramValue = deliverer;
}
if(paramName == "delivpos"){
paramValue = deliverer_pos;
}
}); //<--------------- ERROR HERE
report->printExec();
基本上,我创建了一个QtRPT指针report
并用它将我的代码数据连接到xml文件。很直接。
但是,在编译时,我得到以下错误,全部来自指示的行:
C:\ .. ...\reportwindow.cpp:189: error: no matching function for call to 'reportWindow::connect(QtRPT*&, void (QtRPT::*)(int, QString, QVariant&, int), reportWindow::on_acic_report_btn_clicked()::<lambda(int, QString, QVariant&, int)>)'
});
^
C:\... ...\reportwindow.cpp:189: error: template argument for 'template<class Func1, class Func2> static typename QtPrivate::QEnableIf<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)' uses local type 'reportWindow::on_acic_report_btn_clicked()::<lambda(int, QString, QVariant&, int)>'
});
^
C:\... ...\reportwindow.cpp:189: error: template argument for 'template<class Func1, class Func2> static typename QtPrivate::QEnableIf<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)' uses local type 'reportWindow::on_acic_report_btn_clicked()::<lambda(int, QString, QVariant&, int)>'
});
^
我是qt中的新手,但是我可以从错误和一些研究中得知,stackoverflow中的连接需要在其参数中指针,report
和setValue
都是指针。
导致此错误的原因是什么?输入数据时使用的if语句? setValue
本身?
另外,作为旁注,有没有更好的QtRPT实现,或者可能是一个显示一些示例代码的网站?似乎网站上没有任何奇怪的内容。
答案 0 :(得分:1)
我相信你是以错误的方式调用QtRpt生成器,试试这个:
connect(ui->printButton, SIGNAL(clicked()), this, SLOT(PrintReport()));
void YourApp::PrintReport() {
QString reportTemplate = "myreport.xml";
QtRPT *report = new QtRPT(this);
report->loadReport(reportTemplate );
// Use this only if you are going to print from table
report->recordCount << ui->tableView->rowCount();
QObject::connect(report, SIGNAL(setValue(const int, const QString, QVariant&, const int)),
this, SLOT(setValue(const int, const QString, QVariant&, const int)));
report->printExec();
}
void YourApp::setValue(const int recNo, const QString paramName, QVariant ¶mValue, const int reportPage) {
if(paramName == "dateprep"){
paramValue = date_prepared;
}
if(paramName == "acic"){
paramValue = acic_no;
}
if(paramName == "fund"){
paramValue = fund_type;
}
if(paramName == "bankaccnt"){
paramValue = bank_account_no;
}
if(paramName == "bankname"){
paramValue = bank_name;
}
if(paramName == "ALOBS No."){
paramValue = alobs_no;
}
if(paramName == "Check No."){
paramValue = check_no;
}
if(paramName == "Payee"){
paramValue = payee;
}
if(paramName == "Check Date"){
paramValue = date_of_check;
}
if(paramName == "Amount"){
paramValue = amount;
}
if(paramName == "Total"){
paramValue = total_amount;
}
if(paramName == "totalwords"){
paramValue = pesoword;
}
if(paramName == "ccname"){
paramValue = certifier;
}
if(paramName == "ccpos"){
paramValue = certifier_pos;
}
if(paramName == "appname"){
paramValue = approver;
}
if(paramName == "apppos"){
paramValue = approver_pos;
}
if(paramName == "delivname"){
paramValue = deliverer;
}
if(paramName == "delivpos"){
paramValue = deliverer_pos;
}
}