Results 1 to 6 of 6

Thread: Writing Data Aware Forms in QT4.

  1. #1
    Join Date
    May 2006
    Posts
    20
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Writing Data Aware Forms in QT4.

    I posted this question in the QTForums.org, but no one seems to have a suggestion.

    In QT 3.2, I wrote a simple client application to view, update and insert service tickets into a database. I wanted the data displayed in a form and not a table, so I used the QSqlForm class. There are several QSqlForm examples shown in QT3 books and the online doc. QT 4.1 no longer uses QSqlForm. While the class is still available, QT 4.1 uses the model view concept for displaying data. There are a few model/view convenience classes, but those are table and list views.

    I've re-written the app I had written in 3.2 to work with QT4. Instead of using QSqlForm, I have a function that populates all the fields with the data from a query's current record. I use a similar function to insert and update data records. But, I'm not sure this is the best approach for writing a client application. How does one write a form style application in QT4 using the model view architecture? The model view design interests me, because it appears to allow one to easily write a 3-tier client/server application in QT. If my understanding of the model/view is incorrect, please let me know.

    Thanks,
    Glenn

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Writing Data Aware Forms in QT4.

    Quote Originally Posted by gsQT4
    I posted this question in the QTForums.org, but no one seems to have a suggestion.
    QtForum is practically dead.

    In QT 3.2, I wrote a simple client application to view, update and insert service tickets into a database. I wanted the data displayed in a form and not a table, so I used the QSqlForm class. There are several QSqlForm examples shown in QT3 books and the online doc. QT 4.1 no longer uses QSqlForm. While the class is still available, QT 4.1 uses the model view concept for displaying data. There are a few model/view convenience classes, but those are table and list views.

    I've re-written the app I had written in 3.2 to work with QT4. Instead of using QSqlForm, I have a function that populates all the fields with the data from a query's current record. I use a similar function to insert and update data records. But, I'm not sure this is the best approach for writing a client application. How does one write a form style application in QT4 using the model view architecture? The model view design interests me, because it appears to allow one to easily write a 3-tier client/server application in QT. If my understanding of the model/view is incorrect, please let me know.
    First step is to define your model properly. I assume you know (or will find a way) how to do it. The second step is to connect the model to your widgets. Unfortunately Qt4 itself doesn't provide an easy way to do this with all the widgets, but signals and slots are your friends here. In my opinion you should implement a QObject subclass which would serve as a controller between the model and widgets handling different fields. The controller has to do two things:
    1. Make sure widgets always display up to date data
    2. Commit changes made by the widgets to the model

    For the first step, model signals like dataChanged(), layoutChanged() and reset() will be usefull.
    For the second, you should connect signals emitted when the data changes from the widgets to your controller.

    The last thing to do is to provide an architecture for connecting and disconnecting widgets from the controller.

    I started to implement such a solution myself, but currently I don't have time to finish my controller architecture, but it's no big deal.

  3. #3
    Join Date
    May 2006
    Posts
    20
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Writing Data Aware Forms in QT4.

    Thanks for the suggestions wysota. I'll see if I can figure out how to make it work.

    It sounds like this approach has the application displaying data real time, instead of working from the last query to the database. Is the model/view concept the trend for database client applications?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Writing Data Aware Forms in QT4.

    Quote Originally Posted by gsQT4
    Thanks for the suggestions wysota. I'll see if I can figure out how to make it work.
    Sure you can.

    It sounds like this approach has the application displaying data real time, instead of working from the last query to the database.
    Yes.

    Is the model/view concept the trend for database client applications?
    The model/view concept doesn't assume any specific backend for storing data. It works with both dynamic and static data.

  5. #5
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Writing Data Aware Forms in QT4.

    Hi all !
    So i also have this problem
    Wysota is your approach correct today(becouse i see last post in thread near year old) ? Or maiby community find something else ?
    Thx...
    a life without programming is like an empty bottle

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Writing Data Aware Forms in QT4.

    QDataWidgetMapper is the proper solution since Qt 4.2 (it does exactly what I wanted it to).

  7. The following user says thank you to wysota for this useful post:

    zlatko (21st March 2007)

Similar Threads

  1. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17
  2. Replies: 16
    Last Post: 7th March 2006, 15:57

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.