Another "change qt application language at runtime" thread.
-
hmm .. which compiler are you using ?
-
you could try to replace 'template <class T>' by 'template <typename T>'
-
and for no warnings compilation add: Q_UNUSED(obj); into the enventFilter()
-
But the error happens before this? I have only written:
@template <class T>
class MyTranslation : public QObject
{
T* m_t;public:
MyTranslation() : m_t(0) {}
~MyTranslation() { if (m_t) m_t->QWidget::removeEventFilter(this); m_t = 0; }
};@And it gives the error...
-
I have found some help in internet, seems that your interface (eclipse) not the compiler the problem.
"here some indication":stackoverflow.com/questions/6503551/opencv-type-iplimage-could-not-be-resolved
-
Thank you :)
I wrote the code in Qt Creator instead of Eclipse, and no errors appear in the MyTranslation.h file.
I am now trying to set up the "MyWidget.h" file.
First of all I can't inherit from Ui::MyWidget. Can this have something to do with MyWidget being a base class for all my ui's?
Secondly, if I leave out Ui::MyWidget, but inherit from MyTranslation<MyWidget>, my ui's seems to get errors, when it comes to the signal and slot connections made.
"reference to 'connect' is ambiguous"
-
If you couldn't inherits from the Ui::MyWidget you should adapt the code in the handler to find the restranslateUI(), or move the retranslateUI() call in the translationChanged() function.
yes, because you have 2x QObject inheritence. Use at the place the on_awidget_asignal() slots or in this case use QWidget::connect().
-
Sorry, regarding the way I do multiple inheritence, you could find help in the Qt documentation: "Using a Design UI File in Your Application", pay a look to the last chapter:"Automatic Connections".
-
You inherit twice from QObject:
@
class MyTranslation : public QObject
class MyWidget: public QWidget, public Ui::MyWidget, public MyTranslation<MyWidget>
@So you inherit from QObject via QWidget (which is a QObject subclass) and via MyTranslation. This is not supported!
-
It's supported, you should simply take care of the conflict. But we could do it through delegations (I take in consideration all what we say):
@
#include <QtCore/QObject>template <class T>
class MyTranslator : public QObject
{
T* m_t;public:
MyTranslator(T* widget)
: m_t(widget)
{
m_t->installEventFilter(this);
}~MyTranslator() { m_t->removeEventFilter(this); } bool eventFilter(QObject *obj, QEvent *event) { Q_UNUSED(obj); if (m_t && event->type() == QEvent::LanguageChange) { // not automatally retranslation m_t->T:translationChanged(); } return false; }
};
#include <QtGui/QWidget>
#include <ui_MyWidget.h>
#include <MyTranslator.h>class MyWidget: public QWidget
{
Q_OBJECTpublic: MyWidget(QWidget* parent = 0) : QWidget(parent), m_translator(this) { ui.setupUi(this); } virtual ~MyWidget() {} virtual void translationChanged() { ui.restranslateUi(); qWarning() << "translator changed"; } private: MyTranslator<MyWidget> m_translator; Ui::MyWidget ui;
};
@ -
The "docs of moc":http://doc.qt.nokia.com/4.7/moc.html#multiple-inheritance-requires-qobject-to-be-first state it clearly:
bq. Multiple Inheritance Requires QObject to Be First
If you are using multiple inheritance, moc assumes that the first inherited class is a subclass of QObject. Also, be sure that only the first inherited class is a QObject.
[emphasis by me, Volker] -
Yes, I do both variation (just for you)!
The inherited and the delegated! Both are correct ... just now choose the one you want :).
-
Even the multiple inherited is correct because (to take the sitation of Volker) the first inherited IS a QObject (QWidget is a QObject)!! :)
-
[quote author="BilbonSacquet" date="1321629111"]Even the multiple inherited is correct because (to take the sitation of Volker) the first inherited IS a QObject (QWidget is a QObject)!! :)[/quote]
Don't pick what you want to have and leave out the annoying details that make your design fail!
bq. Also, be sure that only the first inherited class is a QObject.