Results 1 to 6 of 6

Thread: Programming desgin

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2013
    Posts
    45
    Thanks
    6
    Thanked 6 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Programming desgin

    Hello,

    I have a class Document and a class Form. I want Document class to have access to form class.
    These are my two approaches -

    Approach 1:
    Approach 1 project found here.
    mainwindow.cpp
    Qt Code:
    1. ...
    2. // Inside MainWindow init method
    3. Document* document = new Document();
    4. setCentralWidget(document->currentForm());
    5. ...
    To copy to clipboard, switch view to plain text mode 

    document.cpp
    Qt Code:
    1. ...
    2. Document::Document()
    3. {
    4. form = new Form();
    5. }
    6.  
    7. Form* Document::currentForm()
    8. {
    9. return form;
    10. }
    11. ...
    To copy to clipboard, switch view to plain text mode 

    Approach 2:
    Approach 2 project found here.
    mainwindow.cpp
    Qt Code:
    1. ...
    2. // Inside MainWindow init method
    3. Form* form = new Form();
    4. setCentralWidget(form);
    5. Document* document = new Document();
    6. document->setCurrentForm(form);
    7. ...
    To copy to clipboard, switch view to plain text mode 

    document.cpp
    Qt Code:
    1. ...
    2. void Document::setCurrentForm(Form* currentForm)
    3. {
    4. form = currentForm;
    5. }
    6. ...
    To copy to clipboard, switch view to plain text mode 

    which design should I use?
    I want to follow Qt's design patterns.

    Thanks
    Last edited by scarecr0w132; 1st January 2015 at 05:53.

Similar Threads

  1. Qt C++ CGI programming
    By karankumar1609 in forum General Programming
    Replies: 7
    Last Post: 4th October 2019, 12:56
  2. MMX Programming
    By vhptt in forum Newbie
    Replies: 3
    Last Post: 19th November 2013, 05:10
  3. Is this a QT programming?
    By knuxie1135 in forum Newbie
    Replies: 1
    Last Post: 7th November 2012, 16:09
  4. Qt programming
    By archanasubodh in forum Installation and Deployment
    Replies: 2
    Last Post: 6th March 2008, 08:55
  5. QT COM Programming
    By sarav in forum Newbie
    Replies: 5
    Last Post: 24th February 2007, 13:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.