Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Connection QT and NCReport



  • Hello every one,
    I am working on qt and would like to know if it is possible to connect qt and NCReport. To view qt content as PDF using NCRepot?
    here is my code:

    report.pro
    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    CONFIG += c++11

    You can make your code fail to compile if it uses deprecated APIs.

    In order to do so, uncomment the following line.

    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

    SOURCES +=
    main.cpp
    widget.cpp

    HEADERS +=
    widget.h

    FORMS +=
    widget.ui

    #QMAKE_CXXFLAGS += -std =gnu++14

    Default rules for deployment.

    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    -----------------widget.h-----------------
    #ifndef WIDGET_H
    #define WIDGET_H

    #include <QWidget>

    QT_BEGIN_NAMESPACE
    namespace Ui { class Widget; }
    QT_END_NAMESPACE

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

    private slots:
    void on_agregarButton_clicked();

    void on_eliminarButton_clicked();
    
    void on_imprimirButton_clicked();
    

    private:
    enum {
    ID,
    NOM,
    AGE,
    SALAIRE
    };
    Ui::Widget *ui;
    };
    #endif // WIDGET_H
    ---------------widget.cpp---------------------
    #include "widget.h"
    #include "ui_widget.h"

    Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
    {
    ui->setupUi(this);
    const QStringList titles {"ID", "NOM","AGE","SALAIRE"};
    // QString nombre = ui->nombreLineEdit->text();
    ui->tableWidget->setColumnCount(titles.size());
    ui->tableWidget->setHorizontalHeaderLabels(titles);
    // ui->tableWidget->setColumnCount(4);
    ui->idSpinBox->setMinimum(0);
    ui->idSpinBox->setMaximum(INT_MAX);
    ui->edadSpinBox->setMinimum(0);
    ui->edadSpinBox->setMaximum(INT_MAX);
    ui->salarioDoubleSpinBox->setMinimum(0.0);
    ui->salarioDoubleSpinBox->setMaximum(99999999.0);
    }

    Widget::~Widget()
    {
    delete ui;
    }

    void Widget::on_agregarButton_clicked()
    {
    const QString id = QString::number(ui->idSpinBox->value());
    const QString nombre = ui->nombreLineEdit->text();
    const QString age = QString::number(ui->edadSpinBox->value());
    const QString salario = QString::number(ui->salarioDoubleSpinBox->value());
    const int rowCount = ui->tableWidget->rowCount();
    ui->tableWidget->insertRow(rowCount);
    ui->tableWidget->setItem(rowCount, ID, new QTableWidgetItem(id));
    ui->tableWidget->setItem(rowCount, NOM, new QTableWidgetItem(nombre));
    ui->tableWidget->setItem(rowCount, AGE, new QTableWidgetItem(age));
    ui->tableWidget->setItem(rowCount, SALAIRE, new QTableWidgetItem(salario));
    ui->idSpinBox->clear();
    ui->nombreLineEdit->clear();
    ui->edadSpinBox->clear();
    ui->salarioDoubleSpinBox->clear();
    ui->idSpinBox->setFocus();
    }

    void Widget::on_eliminarButton_clicked()
    {
    ui->tableWidget->removeRow(ui->tableWidget->currentRow());
    }

    void Widget::on_imprimirButton_clicked()
    {

    }
    --------------------main.cpp----------------------
    #include "widget.h"

    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    a.setStyle("fusion");
    Widget w;
    w.show();
    return a.exec();
    }
    thank you,


  • Lifetime Qt Champion

    @Oussou Please read their documentation: NCReportGuide_en.pdf
    Especially chapter "3.12 Integrating NCReport in Qt applications"



  • @jsulm thank you


Log in to reply