Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

R1832 patch: Add Q_OBJECT to all Component subclasses

2 posters

Go down  Message [Page 1 of 1]

royqh1979



Component is inherited from QObject, but it and all it's children classes don't have Q_OBJECT macro.

This makes translations won't work.

I'm not sure if it is purposed to do that, if not, this is the patch.

A clean/rebuild is needed before build the project.
Attachments
R1832 patch: Add Q_OBJECT to all Component subclasses Attachmenttrans.zip
You don't have permission to download attachments.
(9 Kb) Downloaded 0 times

arcachofo

arcachofo

I didn't even remember about this.This is something to solve.

The Q_OBJECT macro adds quite a bit of code, increasing the size of the executable and compile time.
In some cases it is used for several things, then it is included.
But in most cases it is only used for translation. In this cases we could use some alternative.

For example, intead ot Q_QOBJECT we could use:
Q_DECLARE_TR_FUNCTIONS( ClassName );
And #include

Or create our own macro and avoid the include.

arcachofo

arcachofo

I think this could be a solution:

In each cpp file whith tr() add this macro:
#define tra(str) QCoreApplication::translate("ClassName",str)

And replace tr("srting") by tra("string")

In most cases no extra include is needed.
In some cases we could need #include
But all this in in the cpp, not in the header.

royqh1979



arcachofo wrote:I didn't even remember about this.This is something to solve.

The Q_OBJECT macro adds quite a bit of code, increasing the size of the executable and compile time.

Executable size is increased by 150kb after Q_OBJECT added.

I think it's not much and isn't worth the extra work.

R1832 patch: Add Q_OBJECT to all Component subclasses Snap112

arcachofo

arcachofo

Executable size is increased by 150kb after Q_OBJECT added.

I think it's not much and isn't worth the extra work.
Yes, that is not much, but this is only part of the "cleaning".
The final goal is to avoid inheritance from QObject as much as posible, specially for Components.
There are still some issues to solve and could be that at the end it is not worth.

I will have a look and try to get a better picture...

royqh1979



arcachofo wrote:
Executable size is increased by 150kb after Q_OBJECT added.

I think it's not much and isn't worth the extra work.
Yes, that is not much, but this is only part of the "cleaning".
The final goal is to avoid inheritance from QObject as much as posible, specially for Components.
There are still some issues to solve and could be that at the end it is not worth.

I will have a look and try to get a better picture...

Good news: It seems lupdate doesn't check if tr is in an QObject subclass.

so we just need to overwrite tr();

arcachofo

arcachofo

Good news: It seems lupdate doesn't check if tr is in an QObject subclass.

so we just need to overwrite tr();
Thanks.
Then it is enough to add this to cpp instead of Q_OBJECT macro in header:
#define tr(str) QCoreApplication::translate("ClassName",str)

I'm converting slots in context menus to non-QObject and some other stuff to try to get rid of QObject inheritance.
So I will do this as well.

royqh1979



arcachofo wrote:
Good news: It seems lupdate doesn't check if tr is in an QObject subclass.

so we just need to overwrite tr();
Thanks.
Then it is enough to add this to cpp instead of Q_OBJECT macro in header:
#define tr(str) QCoreApplication::translate("ClassName",str)

I'm converting slots in context menus to non-QObject and some other stuff to try to get rid of QObject inheritance.
So I will do this as well.

But I'm not sure if it will work in Qt 6.
I'm working on a patch for overwrite tr()

arcachofo

arcachofo

But I'm not sure if it will work in Qt 6.
Ok... I have no idea about that.
Do you mean tr() or also some other thing?

I'm working on a patch for overwrite tr()
Nice, then I will wait for that.

royqh1979



Patch for tr().

I created a macro "DECL_TR_FUNC()", which will define a tr() function.
This tr() function will overwrite Q_Object's default tr() if it exists.

arcachofo wrote:
But I'm not sure if it will work in Qt 6.
Ok... I have no idea about that.
Do you mean tr() or also some other thing?

I'm working on a patch for overwrite tr()
Nice, then I will wait for that.
Attachments
R1832 patch: Add Q_OBJECT to all Component subclasses Attachmenttrans.zip
You don't have permission to download attachments.
(10 Kb) Downloaded 1 times

arcachofo likes this post

arcachofo

arcachofo

We may have an issue here:
In component.h tr() is defined and then redefined in each component?

arcachofo

arcachofo

I implemented tr() with simple macros at Rev 1835.

royqh1979



arcachofo wrote:I implemented tr() with simple macros at Rev 1835.

In some classes, component name in tr() is not the same as the class name, and translations doesn't work.

And strings in CircuitView not translated.

Here's the patch and updated zh_CN translation.
Attachments
R1832 patch: Add Q_OBJECT to all Component subclasses Attachmenttrans-2.zip
You don't have permission to download attachments.
(3 Kb) Downloaded 1 times
R1832 patch: Add Q_OBJECT to all Component subclasses Attachmentsimulide_zh_CN.zip
You don't have permission to download attachments.
(17 Kb) Downloaded 1 times

arcachofo

arcachofo

Thanks. patch applied at Rev 1840.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum