How to add form to existing class?

Viewed 37

I have an existing (QCreator build) class derived from QTextEdit

 class CCC_MdiChild : public QTextEdit

I like to add GUI form like so

I have no issue creating new form.ui and adding it to the project.

I do not know how to modify existing constructor ( and its definition ) to include "form.ui" .

I am asking for an assistance / help to do that.

Here is my current constructor

Sorry , I did try to format the code but I could not "cut and paste " it as code . ( and I could not reedit it after it was edited once ) Since I did realize my poor formatting any automated comments in that aspect will be ....

1 Answers

The required steps are documented here. For completeness, they are:

  • Since you've added the .ui file to the project, the UI compiler should generate the corresponding header ui_form.h, which you should #include in the header for your class;
  • Add a private member to your class of the type defined in this header, which is in namespace Ui and takes its name from your .ui file;
  • Call the object's setup function as setupUi(this) in the constructor(s) of your class.

Alternatively, you also use multiple inheritance, or avoid including ui headers in header files with the slightly more complicated forward-declared pointer member approach.

Related