The key knowledge is closeCode...
Please read the code carefully
Original article
Reprinted please keep this link http://blog.csdn.net/siren0203
Header file
Mainwidget. h
# Ifndef maindwidget_h <br/> # define maindwidget_h <br/> # include <qmainwindow> <br/> # include <qobject> <br/> class qworkspace; <br/> class mainwidget: Public qmainwindow {<br/> q_object <br/> Public: <br/> mainwidget (qwidget * parent = 0 ); </P> <p> PRIVATE: <br/> qworkspace * workspace; </P> <p> }; </P> <p> # endif // maindwidget_h <br/>
Implementation Code
Main. cpp
# Include <qapplication> <br/> # include <qworkspace> <br/> # include <qtextedit> <br/> # include "maindwidget. H "<br/> mainwidget: mainwidget (qwidget * parent): qmainwindow (parent) {<br/> // create a qworkspace object <br/> workspace = new qworkspace (this ); <br/> // set the central window of the main form to the qworkspace object to implement multiple la s of the window <br/> setcentralwidget (workspace ); </P> <p> // create window 1 <br/> qmainwindow * window1 = new qmainwindow (this ); <br/> window1-> setwindowtitle (TR ("Window 1"); <br/> qtextedit * edit1 = new qtextedit (this ); <br/> edit1-> settext ("Window 1"); <br/> window1-> setcentralwidget (edit1 ); <br/> // create window 2 <br/> qmainwindow * window2 = new qmainwindow (this ); <br/> window2-> setwindowtitle (TR ("window 2"); <br/> qtextedit * edit2 = new qtextedit (this ); <br/> edit2-> settext ("window 2"); <br/> window2-> setcentralwidget (edit2 ); <br/> // create window 3 <br/> qmainwindow * window3 = new qmainwindow (this ); <br/> window3-> setwindowtitle (TR ("window 3"); <br/> qtextedit * edit3 = new qtextedit (this ); <br/> window3-> setcentralwidget (edit3); <br/> // insert a subwindow to a workspace to implement multiple windows. <br/> Workspace-> addwindow (window1 ); <br/> Workspace-> addwindow (window2); <br/> Workspace-> addwindow (window3 ); </P> <p >}</P> <p> int main (INT argc, char ** argv) {<br/> qapplication app (argc, argv ); <br/> mainwidget main; <br/> main. show (); <br/> return app.exe C (); <br/>}< br/>
..