QtRpt report from Databse



  • Hello ,
    I am using QtRpt for creating reports. I can generate report from tablewidget. When I trying to get data from database then I facing problem . Anyone can help in this?

    Below is My Code.

    void MainWindow::on_btnGenrateReport_clicked()
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("/home/gtek/Work/validscan_proj/validscan_db");
        if(!db.open())
        {
            qDebug()<<"Database not Open"<<endl;
        }
        else
        {
            QSqlQuery  qry;
            qry.prepare("select * from vs_channel");
            if(!qry.exec())
            {
                qDebug()<<"Error in Query"<<endl;
            }
            else
            {
                QtRPT *report = new QtRPT(this);
                while(qry.next())
                {
    
                qDebug()<<qry.value(12).toString()<<endl;
                qDebug()<<qry.value(1).toString()<<endl;
                qDebug()<<qry.value(6).toString()<<endl;
    
                    report->loadReport(":/chreport.xml");
                    connect(report,&QtRPT::setValue,[&](const int recNo,
                            const QString paramName, QVariant &paramValue, const int reportPage)
                    {
                        (void) reportPage;
                        if(paramName=="channel_id")
                        {
                            paramValue=(recNo,qry.value(12).toString());
                            qDebug()<<paramValue<<endl;
                        }
                        if(paramName=="channel_tag")
                        {
                            paramValue=(recNo,qry.value(1).toString());
                            qDebug()<<paramValue<<endl;
                        }
                        if(paramName=="unit")
                        {
                            paramValue=(recNo,qry.value(6).toString());
                            qDebug()<<paramValue<<endl;
                        }
    
    
                    });
    
                }report->printExec();
            }
    
        }
    }
    

  • Lifetime Qt Champion

    Hi,

    QtRPT is not an official Qt module, so you should try contacting its author or use their forum.

    In any case, you should also explain exactly what you are expecting and what you are getting.



  • Hello,
    This problem is solved.

    here is the right code.

    void MainWindow::on_btnGenrateReport_clicked()
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("/home/gtek/Work/validscan_proj/validscan_db");
        if(!db.open())
        {
            qDebug()<<"Database not Open"<<endl;
        }
        else
        {
            QSqlQuery  qry;
            qry.prepare("select * from vs_channel");
            if(!qry.exec())
            {
                qDebug()<<"Error in Query"<<endl;
            }
            else
            {
                QtRPT *report = new QtRPT(this);
                while(qry.next())
                {
                   p = new pojo();
                   p->setChannel_id(qry.value(12).toString());
                   p->setChannel_tag(qry.value(1).toString());
                   p->setUnit(qry.value(6).toString());
    
                    plist.push_back(p);
               }
    
                report->loadReport(":/chreport.xml");
                report->recordCount.append(plist.count());
               
    
               connect(report,&QtRPT::setValue,[&](const int recNo,
                            const QString paramName, QVariant &paramValue, const int reportPage)
                {
                    (void) reportPage;
                    if(paramName=="channel_id")
                    {
                        paramValue=plist[recNo]->getChannel_id();
    
                    }
                    if(paramName=="channel_tag")
                    {
                        paramValue=plist[recNo]->getChannel_tag();
                    }
                    if(paramName=="unit")
                    {
                        paramValue=plist[recNo]->getUnit();
                    }
    
                });
    
              
    
                report->printExec();
            }
    
        }
    }
    

    I had created one pojo class for getter setter method.



  • @Neel-0 where can i get the full source code


  • Lifetime Qt Champion

    Hi,

    Using the answer to a simple query.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.