Thanks, but it's still not clear for me.
But if you use designer, you can let it generate slots and connections too.
I know but many of the slots I have don't show in QtDesigner (i.e. Phonon VideoPlayer::play()) , so I'd rather put them all in one place - is the correct place MainWindow constructor? I thought it might be better to connect a widget's signals, or slots, when that widget is instantiated. I.e. in the widgets constructor tell it which slots to connect to. Which goes back to my question about where or if I can access the constructor of widgets added in QtDesigner.
Always, and I want to repeat this: always have an object fully initialized in the constructor. You WILL pull your hear out when you use a function before a variable is initialized.
My question is whether all models accessed from multiple views should be properties of MainWindow. I.e. MainWindow has 50 model objects associated with my 50 db tables.
A view without a model is like a car without an engine. It just sits there. It's not mandatory, but it's common sense to let at least every view have a model.
My question is whether MainWindow constructor is the correct place to attach views (with MainWindow as parent) and models.
If you can't get to the results by using an event filter or signals and slots or other methods (other than subclassing), then yes, you might want to subclass
My question is whether it's "standard" to subclass a widget (and then promote in in QtDesigner) to set a property in it's constructor, or whether again I set properties of these widgets in MainWindow constructor. I.e. I want to hide the first column in QTableView. This is not available in QtDesigner, so where is "usual" place to set this property? You say to set in MainWindow constrcutor - so my MainWindow constructor calls 100's of lines of code to set 100 different properties for all child widgets of MainWindow - is this standard?
There's the main window constructor of course.
This is my question, the view constructor is not the same as MainWindow constructor - I would think it makes more sense to set properties of widget in widget constructor so it is modular (i.e. hide column of QTableView in QTableView constructor), rather than using parent widgets constructor (MainWindow) to set properties of child widget.
One model connected to two views: change an item in the model -> both views get updated at the same time.
That's the beauty of the model view design pattern. It was designed to do this.
Yes, this is what I want - so that means both views should reference the same model attached to MainWindow as a property?
I suggest using Qt Creator. Maybe there's a plugin that does what you want.
Actually I mean an example project that uses clean, logical design with QtDesigner-created widgets and SQL backend. Maybe I should focus on looking through all the example projects and demos. The thing is they usually are small and don't deal with dozens of views and models.
In a nutshell, I want to know if this is the best practice for Qt GUI application:
mainwindow.h
...
{
Q_OBJECT
...
private:
... (etc, etc)
}
...
class MainWindow : public QMainWindow
{
Q_OBJECT
...
private:
QSqlTableModel *m_user;
QSqlTableModel *m_group;
QSqlTableModel *m_activity;
QSqlTableModel *m_schedule;
QSqlTableModel *m_location;
QSqlTableModel *m_event;
QSqlTableModel *m_admin;
QSqlTableModel *m_venue;
... (etc, etc)
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
//MainWindow constructor
MainWindow::MainWindow()
{
//instantiate DB and attach all model properties to DB tables
create DBConnection();
attachModelsToDB();
//set all properties of child widgets
setupChildWidgets();
//connect all QAbstractItemView (sub)classes to models
connectViewsToModels();
//connect all signals and slots for all child widgets
connectSignalsAndSlots();
}
//MainWindow constructor
MainWindow::MainWindow()
{
//instantiate DB and attach all model properties to DB tables
create DBConnection();
attachModelsToDB();
//set all properties of child widgets
setupChildWidgets();
//connect all QAbstractItemView (sub)classes to models
connectViewsToModels();
//connect all signals and slots for all child widgets
connectSignalsAndSlots();
}
To copy to clipboard, switch view to plain text mode
Bookmarks