我正在尝试将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 &paramValue,
        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研究中看出,connect需要在其参数中使用指针,reportsetValue都是指针。

是什么导致此错误?输入数据时使用的if语句? setValue本身?

另外,作为附带说明,QtRPT是否有更好的实现方式,或者是否有显示一些示例代码的站点?似乎网站上没有任何奇怪的东西。

最佳答案

我相信您以错误的方式调用了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 &paramValue, 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;
    }
}

08-05 21:42