[Interest] QSortFilterProxyModel slow updating sql model attached

Linos info at linos.es
Wed May 2 10:01:50 CEST 2012


El 02/05/12 01:51, David Boosalis escribió:
> I've not put much stock in the QSqlQueryModel, but instead done my models
> derived from  QStandardModel.  This requires you to write more code for the SQL
> transactions using QT's SQL module (or your own).  Granted you have to write
> more code and you don't get notices from outside changes to the database. But
> with your own mode,l proxy filters are easier to implement.
> 
> Taking it a bit further I create my own database class, which does all the sql
> stuff.  For example part of my Database class looks like this:
> 
> 
> class Database : public QObject {
>   Q_OBJECT
>     public:
>   enum {OK=0,Error=1,SQL_ERROR,TableDoesNotExists,TableFormatBad,EntryExists,
>     EntryDoesNotExists};
> 
>   typedef  enum {Users,Profiles,UssageLog,Models,...NumOfTables} TableType;
>          
>   enum {NameSize=32,DescriptionSize=256};
>   static QString tableNames[NumOfTables];
>   static QString arguments[NumOfTables];
>   Database(const QString &name,const QString &user,const QString &pass);
>   ~Database();
> 
>   bool createTable(TableType);
>   bool isOpen();
>   bool open();
>   void close();
>   bool tableIsValid(TableType);
>   QString getLastError();
>   QSqlDatabase *getHandle();
>   bool  validateUsersTable();
>   bool  updateUser(User *);
>   bool  updateUsersExpirationDate(int userID,QDate expirationDate);
>   bool  addUser(User *);
>   bool  deleteUser(qint32 userID);
>   UserList  *getUsers();
> .....
> 
> 
> I don't use the database very much. As a result I can read all the records on
> the application startup, cached the records and then be done with the database
> except for seldom inserts, edits, and deletes.  Maybe this approach will work
> for you.
> 
> -David
> 
> PS
> One error I've seen with this approach is that my Qt database handle can go
> state after a day, (This code ran on a server). Meaning that all SQL Queries
> fail to talk to the MySQL database.  I got around this by restarting the server
> code every day from my cron file
> 

Thanks for the advice, I am doing something more like QSqlRelationalTableModel
in my code but much more powerful, it ends using QSqlQueryModel::data for not
changed (in cache) data, but i can edit multiple tables with joins at the same
time and create the correct sql to submit changes taking in account the cache
and such.

Seems that my implementation it is not the best for sort the table on user
action, maybe i could connect the clicks in header to a proper order by change
in the internal model but then unchanged edits would be lost if i don't commit
the changes before and the filter problem remains, would be much better if
QSortFilterProxyModel would be more efficient.

Regards,
Miguel Angel.



More information about the Interest mailing list