Results 1 to 3 of 3

Thread: Concurrent database access and QDataWidgetMapper?

  1. #1
    Join Date
    Aug 2011
    Posts
    16
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Concurrent database access and QDataWidgetMapper?

    Hello,

    i have two database questions:

    1.) Each user should sees a consistent view of the data. What have i to do
    if two or more user have simultaneously access to my database?

    2.) What are the right classes to set a QDataWidgetMapper for my database?

    I have try to use QSqlTableModel, but the problem is, one dataset can include
    data fom the table "Experiment", "Temperatur" and "Qualities". How can i get
    a Model for the QDataWidgetMapper to handle this?

    gui.png

    Qt Code:
    1. model->setTable("Temperatur");
    2. model->setFilter("ExperimentID=" + QString::number(ID));
    3. model->select();
    4.  
    5. mapper->setModel(model);
    6. mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    7. mapper->addMapping(min, model->fieldIndex("min"));
    8. mapper->addMapping(max, model->fieldIndex("max"));
    9. mapper->toFirst();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. CREATE TABLE [Experiment]
    2. (
    3. [ExperimentID] integer NOT NULL PRIMARY KEY AUTOINCREMENT,
    4. [Name] varchar (100) NOT NULL,
    5. [Date] datetime NOT NULL DEFAULT '0000-00-00'
    6. );
    7.  
    8.  
    9. CREATE TABLE [Temperatur]
    10. (
    11. [ExperimentID] integer NOT NULL DEFAULT 0,
    12. [min] integer DEFAULT 0,
    13. [max] integer DEFAULT 0,
    14. [average] integer DEFAULT 0,
    15. ...
    16. );
    17.  
    18. CREATE TABLE[Qualities]
    19. (
    20. [ExperimentID] integer NOT NULL DEFAULT 0,
    21. [material] integer DEFAULT 0,
    22. [fuel] integer DEFAULT 0,
    23. [container] integer DEFAULT 0,
    24. ...
    25. );
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Concurrent database access and QDataWidgetMapper?

    Quote Originally Posted by cyberduck View Post
    1.) Each user should sees a consistent view of the data. What have i to do
    if two or more user have simultaneously access to my database?
    You could poll the database for changes or use an out-of-band communication mechanism to notify other clients when changes have been made

    Quote Originally Posted by cyberduck View Post
    2.) What are the right classes to set a QDataWidgetMapper for my database?

    I have try to use QSqlTableModel, but the problem is, one dataset can include
    data fom the table "Experiment", "Temperatur" and "Qualities". How can i get
    a Model for the QDataWidgetMapper to handle this?
    Using QSqlQueryModel with a query that gets the necessary data from all involved tables?


    Cheers,
    _

  3. #3
    Join Date
    Aug 2011
    Posts
    16
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Concurrent database access and QDataWidgetMapper?

    Hi,

    thank you for the reply.

    So far so good, i got a QSqlRecord from the QSqlQueryModel, but i cant write it back!

    The QSqlQueryModel is read-only and i want change or insert data into the database. How can i do that?

    Can you help me please?

Similar Threads

  1. Prevent concurrent access from different threads?
    By agarny in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2013, 12:44
  2. Adding new record to database from QDataWidgetMapper
    By naptizaN in forum Qt Programming
    Replies: 4
    Last Post: 15th July 2012, 13:19
  3. Replies: 3
    Last Post: 4th August 2010, 18:51
  4. Database access from Qt
    By nimmyj in forum Qt Programming
    Replies: 1
    Last Post: 23rd November 2006, 06:51
  5. Database access from Qt
    By nimmyj in forum General Discussion
    Replies: 1
    Last Post: 16th November 2006, 14:11

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.