Results 1 to 4 of 4

Thread: QDataWidgetMapper and QSqlQueryModel

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

    Question QDataWidgetMapper and QSqlQueryModel

    Hello,

    how can i display some values from my database and write it back?

    That is my QSqlQueryModel
    Qt Code:
    1. model->setQuery("SELECT * FROM Experiment"
    2. "INNER JOIN Temperatur ON Experiment.ExperimentID = Temperatur.ExperimentID"
    3. "INNER JOIN Qualities ON Experiment.ExperimentID = Qualities.ExperimentID");
    To copy to clipboard, switch view to plain text mode 
    I set the model to a QDataWidgetMapper and add mapping for my QSliders
    Qt Code:
    1. mapper->setModel(model);
    2. mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    3. mapper->addMapping(ui.qslider_min, model->record(int_row)->indexOf("min"));
    4. mapper->addMapping(ui.qslider_max, model->record(int_row)->indexOf("max"));
    5. mapper->toFirst();
    To copy to clipboard, switch view to plain text mode 
    The submit fails every time
    Qt Code:
    1. mapper->submit();
    To copy to clipboard, switch view to plain text mode 
    How can i write back the slider-values to my database? Can you help me please?

    Thanks in Advance

  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: QDataWidgetMapper and QSqlQueryModel

    When you say submit() fails, what is the error you are getting?

    Cheers,
    _

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

    Question Re: QDataWidgetMapper and QSqlQueryModel

    Hi,

    sorry for my bad english! The submit fails not directly, mapper->submit() is true.

    The question is, how can i write back the values to my database?

    Can you help me please?

    Thanks in advance.

  4. #4
    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: QDataWidgetMapper and QSqlQueryModel

    Ah!

    The documentation of QSqlQueryModel says: "The model is read-only by default. To make it read-write, you must subclass it and reimplement setData() and flags()."

    Cheers,
    _

Similar Threads

  1. QDataWidgetmapper
    By locus in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2012, 11:24
  2. Advise:Do I need QDataWidgetMapper?
    By fatecasino in forum Newbie
    Replies: 1
    Last Post: 4th March 2011, 01:04
  3. QDataWidgetMapper with QTreeView
    By Nightfox in forum Qt Programming
    Replies: 2
    Last Post: 1st September 2009, 19:58
  4. QDataWidgetMapper
    By rogerholmes in forum Newbie
    Replies: 4
    Last Post: 24th March 2009, 19:32
  5. QCheckBox on QDataWidgetMapper
    By Banjo in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2008, 03:09

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.