Hello everyone, In this article we will talk about how can we use MDI forms in QT GUI with C++ and we will make an example.

Firstly I am using QT 5.11.3 version and we will make our example in this version.Now I am ready to start the article.

First I want to say what MDI does ?

A Multiple Document Interface (MDI) program is to display multiple subwindows in parent window. This is not like single document interface (SDI) applications that can only remove one document at a time. Any window can be MDI window parent. And parent window can show subwindows what we want.

Now lets get started to use mdi screen on QT C++ GUI program.

In our project’s pro file make sure widgets library is added.

After this we need to insert an MDI Area object under Containers to our window:

After insertation the mdi area now we need to put our sub forms inside this mdi area. Now lets do this.

First we need to include our forms classes in header

Then declare them as private or public :

And I want to use Signal/Slot with them. I want to emit a function from subwindow and update somethings in MainWindow. So we need to declare our slot functions header:

We need to declare signals in all windows:

Put this signal declaration inside form1 header:

Put this signal declaration inside form2 header:

Put this signal declaration inside form3 header:

Our SIGNALS are ready to use now.

Now we need to work in mainwindows.cpp file. In here first we are giong to initiate the subwindows. Then set the window settings and sizes. After this we can do whatever we want about subwindow. After configuring the window and adding inside the mdi area, we need to connect subwindow’s SIGNAL and mainwindow’s SLOT.

Here we have created our subwindows and inserted into mdi area. After this we have connected the slots to their signals.

Put these slots in to mainwindow.cpp file. These are slots that we will use to update data from subwindows:,

Now we are ready to use mdi area in our program.

Keep following my articles.

Have a nice coding.

Burak Hamdi TUFAN

LEAVE A REPLY

Please enter your comment!
Please enter your name here