Results 1 to 4 of 4

Thread: updating database

  1. #1
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default updating database

    Does qdatawidgetmapper update databases?

    I used the code that can be found at the link below and modified it just to connect to my database(all i did was change "bool createConnections"; nothing else).

    http://www.trolltech.com/developer/t...ntry&id=147264

    I ran the code and got it to work. I changed
    Qt Code:
    1. #if 1
    2. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    3. #else
    4. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    5. #endif
    To copy to clipboard, switch view to plain text mode 

    to

    Qt Code:
    1. #if 0 //changed 1 to 0;thats all
    2. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    3. #else
    4. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    5. #endif
    To copy to clipboard, switch view to plain text mode 

    and the view was updated perfectly; using the mapped lineEdit . But when i go back to the command prompt and check the database, nothing has changed.

    Can someone tell me how to update the database using the mapped widget?

    My code follows the exact same procedure as that in the link, with only some formatting differences. My mapped widgets does not update the database, the ones in the code at the above URL does not update the database either.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: updating database

    Hi,

    setting the EditStrategy to QSqlTableModel::OnManualSubmit you must apply the changes with
    Qt Code:
    1. bool QSqlTableModel::submitAll ()
    To copy to clipboard, switch view to plain text mode 
    or revert them with
    Qt Code:
    1. void QSqlTableModel::revertAll ()
    To copy to clipboard, switch view to plain text mode 
    .

    In this way you can control all changes and apply them to the model only if are consistent with your application logic.
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: updating database

    Thanks for the response mcosta.

    I should have metioned thought that i tried that (submitAll() that is), but for some reason it did not work

    here are the relevant pieces of code that were added to the code found at the URL:

    Qt Code:
    1. QPushButton *button = new QPushButton("button");
    2.  
    3. hbox->addWidget(button);
    4.  
    5. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    6.  
    7. connect(button,SIGNAL(clicked()),model,SLOT(submitAll()));
    8.  
    9. mapper.setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
    To copy to clipboard, switch view to plain text mode 

    i then ran the code and and clicked my button to call submitAll(), after pressing CTRl+S to call submit() for the mapper. The attribute value in the view changed, but the value in the database remains untouched.

    i found somthing in the docs called :
    Qt Code:
    1. QAbstractItemDelegate::SubmitModelCache
    To copy to clipboard, switch view to plain text mode 

    don't know if it can help, nor do i know how to access the delegate being used by the view to set it.

    It is supposed to tell the delegate to write all cached data to the database.

    any suggestions will be greatly appreciated.

  4. #4
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: (RESOLVED)updating database

    For a detailed description of the problem and solution got to:


    http://www.qtcentre.org/forum/f-qt-p...rror-5370.html

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 08:30
  2. Database access issue
    By Gayathri in forum Newbie
    Replies: 3
    Last Post: 23rd November 2006, 07:41
  3. Database access from Qt
    By nimmyj in forum Qt Programming
    Replies: 1
    Last Post: 23rd November 2006, 06:51
  4. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 17:50
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53

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.