Results 1 to 10 of 10

Thread: Form update problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Form update problem

    I am trying to update my form with the following code by the form won't save the edits.

    Qt Code:
    1. tableModel->select();
    2. QModelIndex index = ui.tableView->currentIndex();
    3. QString sqlQuery = QString("UPDATE %1 SET firstname=:firstname, lastname=:lastname, country=:country, city=:city WHERE id=:id)").arg(tableName);
    4. query.prepare(sqlQuery);
    5. QSqlRecord recordz = tableModel->record(index.row());
    6.  
    7. query.bindValue(":firstname", ui.fEdit->text());
    8. query.bindValue(":lastname", ui.lnEdit->text());
    9. query.bindValue(":country", ui.cEdit->text());
    10. query.bindValue(":city", ui.cityEdit->text());
    11. query.bindValue(":id", recordz.value("id").toInt());
    12. query.exec();
    13. tableModel->submitAll();
    To copy to clipboard, switch view to plain text mode 
    Last edited by thefatladysingsopera; 12th September 2011 at 13:36.

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

    Default Re: Form update problem

    Your code doesn't make any sense. Replace line #13 with tableModel->select(). Of course you will lose all the changes done through the model (if any). Better yet, use QDataWidgetMapper.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Form update problem

    I am already using QDataWidgetMapper to navigate between records.I am writing a simple sqlite manager and this is the first time i have written this much code.I will look into my saveEdits function afresh.Its the only function that remains.

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

    Default Re: Form update problem

    Quote Originally Posted by thefatladysingsopera View Post
    I am already using QDataWidgetMapper to navigate between records.
    Use it to edit the records.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Form update problem

    I don't have a permanent table set in my model so i am choosing what table i want in my model.

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

    Default Re: Form update problem

    I don't see how it is related to the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Form update problem

    Quote Originally Posted by wysota View Post
    Use it to edit the records.
    I have tried it and works to some degree but the problem is that it inserts duplicate records on other tables.

    Unrelated: QSqlTableModel has this function tableName () that returns the name of the currently selected table.In my application,i have my own way of getting the currently selected table but even so,if you are going to be editing the records using QDataWidget mapper in such an arrangement,i reckon its going to be too complicated.

  8. #8
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Form update problem

    Is that extra closing parenthesis in your query after "id=:id" a typo?

  9. The following user says thank you to norobro for this useful post:

    thefatladysingsopera (12th September 2011)

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

    Default Re: Form update problem

    Quote Originally Posted by thefatladysingsopera View Post
    I have tried it and works to some degree but the problem is that it inserts duplicate records on other tables.
    I think it is the problem of your code and not anything inherent to QDataWidgetMapper.

    Unrelated: QSqlTableModel has this function tableName () that returns the name of the currently selected table.In my application,i have my own way of getting the currently selected table but even so,if you are going to be editing the records using QDataWidget mapper in such an arrangement,i reckon its going to be too complicated.
    I really don't see how table names are related to QDataWidgetMapper. The latter works on generic models, it doesn't care about any table names.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    thefatladysingsopera (13th September 2011)

  12. #10
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Form update problem

    Thanks so much for your comments.My code i admit is really not that good and in the coming days i will be taking more Qt classes to improve my skills.

Similar Threads

  1. update form
    By hamidarr in forum Qt Programming
    Replies: 10
    Last Post: 25th June 2011, 21:22
  2. QTableWidget update problem
    By mammenj in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2010, 06:46
  3. Problem with .ui form
    By Fenix Voltres in forum Qt Tools
    Replies: 0
    Last Post: 14th September 2009, 17:37
  4. Form problem
    By dusza in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2009, 22:41
  5. View update problem
    By prakash in forum Qt Programming
    Replies: 6
    Last Post: 17th March 2006, 10:13

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.