fralx / LimeReport

Report generator for Qt Framework
http://limereport.ru/
Other
403 stars 154 forks source link

Adding custom functions #304

Closed yanis60 closed 3 years ago

yanis60 commented 4 years ago

Hi, Is it possible de add custom functions? If yes how?

fralx commented 3 years ago

Hi, sorry for the long waiting! Yes, you can add the custom functions. To do this you can simply register some class inherited from QObject that contains Q_INVOKABLE methods in the report script engine.

class DemoFunctions : public QObject{
    Q_OBJECT
public:
    Q_INVOKABLE QString hello_message(QString msg){
       return QString("Hello %1").arg(msg);
    }
};
......
report->scriptManager()->moveQObjectToScript(new DemoFunctions(), "DemoFunctions");

and use it as $S{DemoFunctions.hello_message("Test")}

yanis60 commented 3 years ago

thank you so much, very useful feature