c++qtqobjectqtranslateqtranslator

QT : QTranslate is not working with QObject subclass


QTranslate is working fine with tr and QObject::tr but when I try to create a subclass of QObject its generating the correct ts file but unable to read it back.

class Reporting : public QObject { };

Reporting::tr("I Am Reporting.");

please help Thanks in advance


Solution

  • That's not a correct QObject. A designating macro and vtable are required, also you might want to provide ownership mechanism.

    class Reporting : public QObject { 
           Q_OBJECT
    
           Reporting (/*whatever*/ QObject* parent = 0 )
           : QObject (parent) /*whatever*/ 
           { /*whatever*/ }
    
           ~Reporting ()
    };
    

    in C++ file

    //virtual destructor
    Reporting ::~Reporting () {}