[QT] Example Analysis of QT tutorial [4] multi-window document [qworkspace]

Source: Internet
Author: User

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/>

 

 

..

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.