Derive UIC generated Qt UI class from custom interface -
Derive UIC generated Qt UI class from custom interface -
i've simple qt question. want automatically generated uic files derived custom interface class in:
intention
class myuiinterface { public: virtual void setupui(qwidget* w) = 0; virtual void retranslateui(qwidget*w) = 0; };
generated uic file should like:
class ui_mywidget { public: void setupui(qwidget* w) { ... } void retranslateui(qwidget* w) { ... } }; namespace ui { class mywidget : public myuiinterface , public ui_mywidget {}; }
why?
every ui::class implement myuiinterface. in each class derives ui::class (see the multiple inheritance approach) able phone call setupui
, retranslateui
makes sense if class derives ui::class class base of operations class either. want every widget derived abstrcat base of operations class mywidgetbase
. consider following:
class mywidgetbase abstract : public qwidget, protected myuiinterface { protected: void changeevent(qevent *e) { qwidget::changeevent(e); if (e->type() == qevent::languagechange) { retranslateui(this); // still abstract here } } }; class mywidget : public mywidgetbase : public ui::mywidget { };
the effect is, every time mywidget::changeevent() callled, retranslateui
of specific class called. otherwise changeevent had reimplemented in each class. bit against "code reuse" concept.
i think qt uic not able handle situation isn't it? there similar way solve problem?
unfortunately, reading xml schema ui files telling not possible automate using uic compiler.
however, unclear me why want implement automatically - if uic somehow manages implement interface, still need add together bodies of functions hand, editing generated .h file, sure there no way include custom code in xml file translate c++ code.
why don't reimplement setupui
, retranslateui
in mywidget
class? every ui class have 1 of these classes, can implement on level, instead of base of operations class. possible missing something, see appropriate way this.
class mywidget : public mywidgetbase, public ui::mywidget { public: void setupui(qwidget* w) { ... } void retranslateui(qwidget* w) { ... } };
with approach, don't need reimplement changeevent()
in of custom widgets, , changeevent
still phone call appropriate retranslateui()
.
qt user-interface interface generator
Comments
Post a Comment