Results 1 to 5 of 5

Thread: QT4 : need database/form/window sample

  1. #1
    Join Date
    Jun 2006
    Posts
    18
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QT4 : need database/form/window sample

    Hi,

    In front of the complexity to start with QT4, I want to build an application managing a database, with one form/window for one table, managing also the relation between table.

    I know that I have to use QSqlTableModel, QSqlRelationalTableModel, etc explain in the page http://doc.trolltech.com/4.1/database.html.

    I have read the tutorial from trolltech, digital fanatics, etc, but I have still the difficulty to START. :-(

    Can someone give me more concrete simple sample of already exist applications, tutorial, or whatelse ?

    Regards.

  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: QT4 : need database/form/window sample

    Probably the simplest example is something like this:


    Qt Code:
    1. #include <QApplication>
    2. #include <QSqlTableModel>
    3. #include <QTableView>
    4. #include <QSqlDatabase>
    5.  
    6. int main(int argc, char **argv){
    7. QApplication app(argc, argv);
    8. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    9. db.setHostName("acidalia");
    10. db.setDatabaseName("customdb");
    11. db.setUserName("mojito");
    12. db.setPassword("J0a1m8");
    13. bool ok = db.open();
    14. if(!ok) return 2;
    15. model.setTable("sometable");
    16. model.setEditStrategy(QSqlTableModel::OnRowChange);
    17. tv.setModel(&model);
    18. tv.show();
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

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

    marvaneke (18th July 2006)

  4. #3
    Join Date
    Jun 2006
    Posts
    18
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT4 : need database/form/window sample

    Thanks for the quick answer.

    It is very interesting and I will try it.

    Suppose I have a database with the table person and the table address, linked each other by the id of the person. Meaning that a person can have multiple address (one for the women and one for the mistress ).

    Can you give me the code with the main.cpp, person.ui, person.cpp, person.h, adress.ui, adress.cpp, address.h.
    I apologize if it is a too long sample to give. Maybe only part of this files is necessary to start ?
    I suppose I have to use the "The Multiple Inheritance Approach" for the chain between the form/window, which is explain on :
    http://doc.trolltech.com/4.1/designe...tance-approach

    Regards.

  5. #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: QT4 : need database/form/window sample

    Here you go... without ui files, as I didn't know what to put in them. I don't know if this is what you wanted but it is something to start with...
    Attached Files Attached Files

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

    marvaneke (18th July 2006)

  7. #5
    Join Date
    Jun 2006
    Posts
    18
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: QT4 : need database/form/window sample

    Hi wysota,

    Once again thanks for the quick answer (and for the mistress tarball, very funny).

    I will start with these two samples.

    I realize that my question was not precise enough.
    If I don't find a solution, I will come back with a more detailled little business case.

    Regards.

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.