Qt-Designer, which approach to ui-files do you use?
-
The documentation offers three ways to use the ui files in your application in a static way.
Since I am just starting my journey with Qt, I would like to know, if you prefer single or multiple inheritance? Are you consistent throughout your programs or do you decide this on a case-by-case basis? If yes, what do you take into consideration? -
I'm using single inheritance with pointer member. It helps to keep UI outside of logic.
-
++pointer_member_method;
When i use designer i use that method too.
I always keep the pointer private (code the necessary signals/slots for that purpose)The multiple inheritance "saves" you from "extra" coding, but it's not really keeping the generated code separated from the code you write.
-
My preference is this;
class MyWidget : public QWidget { public: MyWidget() { widget.setupUi(this); } private: Ui::MyWidget widget; }
The advantage is that this makes sure any changes in your UI file will will not cause conflicts in variable usage inside your 'MyWidget' class which is something that may happen if you double inherit.
The advantage of using the 'widget' as a member instead of as a pointer is one less 'new' and no need to do a 'delete' (which is so easy to forget and sometimes causes mem leaks).
Last; I really like the way of accessing this code in my class;
widget.mySpinbox->value();