Hello,

I would like to have the data contained in an SQL table shown in a treeview (I already have that), but I would like items to be group (kind of filter) by types. See the exemple.

Here is my table "MultimediaFiles" structure:
- id,
- name,
- path,
- type (can be, "picture", "video", "sound").

So, I would like my records to be presented in a treeview like this :

|-- Name --|-- Path --|
------------------------------------
- picture
|- foo.png C:\...
- video
|- bar.avi C:\...
|- toto.mpg C:\...
- sound
|- huhu.wav ...
|- haha.mp3 C:\...

What I already did :

Qt Code:
  1. SQL::SQL()
  2. {
  3. QSqlDatabase mDb = QSqlDatabase::addDatabase( "QMYSQL" );
  4. mDb.setHostName( "localhost" );
  5. mDb.setDatabaseName( "mydb" );
  6. mDb.open();
  7. setupModel();
  8. }
  9.  
  10. void SQL::setupModel()
  11. {
  12. pModel = new QSqlRelationalTableModel();
  13. pModel->setTable( "MultimediaFiles" );
  14. if( !pModel->select() )
  15. {
  16. qDebug() << "pb select";
  17. qDebug() << pModel->lastError().text();
  18. }
  19.  
  20. treeView->setModel( pModel );
  21. /*...*/
  22. treeView->show();
  23. }
To copy to clipboard, switch view to plain text mode 

But it doesn't act as I want : there is no node created.
So, do I miss something, or do I need to make my own model, or add treeItems by hands ?



Thanks in advance.