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
...
// Inside MainWindow init method
Document* document = new Document();
setCentralWidget(document->currentForm());
...
...
// Inside MainWindow init method
Document* document = new Document();
setCentralWidget(document->currentForm());
...
To copy to clipboard, switch view to plain text mode
document.cpp
...
Document::Document()
{
form = new Form();
}
Form* Document::currentForm()
{
return form;
}
...
...
Document::Document()
{
form = new Form();
}
Form* Document::currentForm()
{
return form;
}
...
To copy to clipboard, switch view to plain text mode
Approach 2:
Approach 2 project found here.
mainwindow.cpp
...
// Inside MainWindow init method
Form* form = new Form();
setCentralWidget(form);
Document* document = new Document();
document->setCurrentForm(form);
...
...
// Inside MainWindow init method
Form* form = new Form();
setCentralWidget(form);
Document* document = new Document();
document->setCurrentForm(form);
...
To copy to clipboard, switch view to plain text mode
document.cpp
...
void Document::setCurrentForm(Form* currentForm)
{
form = currentForm;
}
...
...
void Document::setCurrentForm(Form* currentForm)
{
form = currentForm;
}
...
To copy to clipboard, switch view to plain text mode
which design should I use?
I want to follow Qt's design patterns.
Thanks
Bookmarks