Results 1 to 3 of 3

Thread: Model View Help Please

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Model View Help Please

    Hi,

    I am a complete newbie to this, so please bear with me if I ask some stupid questions.

    1. I am having a application in which i need to read/write data from 10 tables from a database in order to show/edit data in the view. My doubt is, will I need to have 10 (one for each table) objects of QAbstractItemModel simultaneuosly in order to read/write from them ?

    2. The view is not the usual table or tree but is combination of QLineEdit, QTextEdit, QLabel..ect. How can these widgets communicate with the model ?

    3. How can I implement undo/redo using MVC ? Some tutorial or link would be great.

    Thanks a lot.

  2. #2
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model View Help Please

    @1
    http://doc.trolltech.com/4.1/qsqlquerymodel.html

    you have to subclass qsqlquerymodel. see the above page for details..

    @2, 3
    dunno, but i'm interested into it..

    edit:
    for 2 you probably have to use the delegate system.
    http://doc.trolltech.com/4.1/model-view-delegate.html


    regards..
    aman..

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Model View Help Please

    Quote Originally Posted by munna
    1. I am having a application in which i need to read/write data from 10 tables from a database in order to show/edit data in the view. My doubt is, will I need to have 10 (one for each table) objects of QAbstractItemModel simultaneuosly in order to read/write from them ?
    It depends if they are related to each other. If you have a complex requirements, I'd suggest subclassing QAbstractTableModel instead of QSqlQueryModel as suggested above as this will give you more control and flexibility.


    2. The view is not the usual table or tree but is combination of QLineEdit, QTextEdit, QLabel..ect. How can these widgets communicate with the model ?
    With Qt4.2+ there is a specialised class called QDataWidgetMapper for that. For earlier versions you have to implement that functionality yourself using signals and slots.

    3. How can I implement undo/redo using MVC ? Some tutorial or link would be great.
    Once again, Qt 4.2 provides a framework for undo/redo. If you have access to Qt Solutions, there is a solution for for undo/redo too. If you wish to implement it yourself, I'd suggest connecting to dataChanged signal in the model or subclassing the model and implementing the functionality in reimplemented setData, insertRow and removeRow.

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  2. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 13:01
  3. Replies: 6
    Last Post: 20th April 2006, 10:23
  4. Model, view, resize to show all data
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 20:59
  5. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 11:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.