Note that there are some explanatory texts on larger screens.

plurals
  1. POQt thick database client architecture
    text
    copied!<p>My goal is to create a thick client to the database. Basically it is all about managing three lists of data.</p> <p>I would like to slice my application into decoupled layers so using Qt's Model/View framework seems natural to me.</p> <ul> <li>When should I create QSql*Model instances?</li> </ul> <p>I need to be able to connect/disconnect to/from the database several times (I have menu items for that). I'm not happy with deleting a bunch of models and creating them once again upon every connect/disconnect.</p> <p>Is there any alternative approach?</p> <ul> <li>Where should I create QSql*Model instances?</li> </ul> <p>I don't think MainWindow or any other GUI-related class is supposed to hold the code like this:</p> <pre><code>m_goodsModel-&gt;setRelation(1, QSqlRelation("Level", "LevelId", "Name")); </code></pre> <p>I want to decouple the GUI from the data structure. Any ideas how to do that?</p> <ul> <li>When and where should I bind my views to models?</li> </ul> <p>I need to represent my three lists in a dozen of ways. If I recreate the models every time I connect/disconnect I will need to inject newly created models into all the views again.</p> <p>It would be great if I could do that only once, but I have no clue how.</p> <ul> <li>What to do with the nasty <code>QSqlTableModel::select()</code> method?</li> </ul> <p>This one drives me crazy. In contrast to other models (e.g. <code>QStringListModel</code>, <code>QFileSystemModel</code>, etc) where the data is ready to use out of the box, models derived from <code>QSqlTableModel</code> are useless until you manually invoke their <code>select()</code> method. Before that invocation the model is empty so as the views using that model; the header data is not populated either, so the view doesn't even know what columns does it have to render.</p> <p>As I cannot avoid <code>select()</code> invocation I wonder where should I put it so that it fits nice? I don't think MainWindow or any other GUI-related classes should contain that code.</p> <ul> <li>Performance and robustness</li> </ul> <p>I'm not happy to reinitialize everything upon db reconnection. It takes too long to do that (I mean during execution). I also would like to avoid crashes during model recreation process as the views may still refer to them.</p> <p>Isn't there any other way to set everything just once and handle reconnection gracefully?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload