c++ - Qt: How to put collection of GUI-Elements into independent SubClass (with seperate *.ui file) -


I am trying to collect the frequently used subset of GUI-elements, in which a subclass, which is "included" The actual GUI can not be asked without re-writing the functionality given later (why not, I want to learn to use it later). Subclasses should use their own * .ui-file and put them into QWidget resding in the actual GUI. After this, to some methods of sub-class, it would be good to reach the actual GUI - such as the position of a button i.e.

But how do I do this?

For the moment, my subclass works and is immediately in the main, but it can not be used with the real GUI because it has been announced only in the main.

My Subclass header file:

  class logger: public QWidget, private Ui :: loggerWidget {Q_OBJECT public: logger (QWidget * parent = 0); Virtual ~ logger (); // Some other stuff ...}  

The manufacturer had to run the setup UI with "parent" instead of "this", but I'm not sure that this is correct - Anyway, it works ... Otherwise, the sub-sections are not displayed in the main window, the real GUI

  logger :: logger (QWidget * parents): QWidget (guardian) {setupUi (guardian); The main window inside // ctor} main.cpp has been created, which it uses its * .ui-File (a widget containing "widget_loggerArea"). By doing so, I can not access the methods of "logger" from "logarte":  
  int main (int argc, char * argv []) {que application app (argc, argv ); Logarithm window; Logger Mylog (window.widget_loggerArea); Window.show (); Return app.exec (); }  

I can not have the constructor of "logger" in the main window "logartest" constructor, because it will be destroyed with emigios and will never enter the event loop. / P>

I'm sure I have not got any concept of object-oriented programming, or the way QT handles its contents ... If someone can keep my nose on it then I will be grateful; -)


I was very stupid ... using a new and removed pointer ... it is very silly, I can not believe it! I recently used more for VHDL, it weakens my C ++ - ...

So, the answer is in the actual GUI class. Constructor:

  testlogger :: testlogger (Q-Mine Window * Parent): Q Menine (Parents) {setupUi (this); MyLog = New Logger (widget_loggerArea); }  

in main.cpp:

  QApplication app (argc, argv); Test logger window; Window.show ();  

And in the manufacturer of logger, setupUi works with "this":

  dfkiLogger :: dfkiLogger (QWidget * parent): QWidget (parent ) {SetupUi (this); }  

Yes, that's right ... Just for perfection, anyone needs to "push in the right direction" like this ...

Edit: The sub-class UI-elements of the sub-class should also be updated in "public":

  class logger: public QWidget, public Ui :: loggerWidget {Q_OBJECT Public: Logger (QWidget * parent = 0); Virtual ~ logger (); }  

Comments