Results 1 to 5 of 5

Thread: QSqlRelationalTableModel QDataWidgetMapper

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlRelationalTableModel QDataWidgetMapper

    OK, I think that maybe I didn't describe my problem clear.

    To simplify:
    QSqlRecord get by record() function from QSqlRelationalTableModel always (?) returns related value for column with foreign key - not original. Is there any method to obtain key value from record?

    For instance:

    Table 1:
    country_id country_name continent_id
    1 France 1
    2 Germany 1
    3 USA 2

    Table 2:
    continent_id continent_name
    1 Europe
    2 North America

    We construct QSqlRelationalTableModel where continent_id in Table_1 is replaced by continent_name from Table_2:

    QSqlRelationalTableMode *model = new QSqlRelationalTableModel;
    model->setTable("Table_1");
    model->setRelation(model->fieldIndex("continent_id"), QSqlRelation("Table_2", "continent_id", "continent_name"));

    Than when we want to read data (first row i.e.) from model we use QSqlRecord:
    ....
    QSqlRecord record = model->record(0);

    Than - if we want to get continent_id field (using value function):

    QString continent_id = record.value("continent_id").toString();

    we will get empty string. Only continent_name is available.
    My goal is to get continent_id, and I don't know how to do it.
    If you put record to qDebug() You will see that record doesn't contain continent_id field.

    regards
    kawoN
    Last edited by kawoN; 2nd March 2010 at 12:17.

  2. #2
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlRelationalTableModel QDataWidgetMapper

    I have the same problem...

  3. #3
    Join Date
    May 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlRelationalTableModel QDataWidgetMapper

    Hi guys,

    same problem here.

    trying to execute a setRecord produces an error.
    It seems like in the QSqlRecord the id field is replaced by the description field.

Similar Threads

  1. Replies: 2
    Last Post: 29th December 2012, 15:14
  2. QDataWidgetmapper
    By locus in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2012, 12:24
  3. QDataWidgetMapper
    By rogerholmes in forum Newbie
    Replies: 4
    Last Post: 24th March 2009, 20:32
  4. QDataWidgetMapper and QSqlRelationalTableModel problem
    By larry104 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 16:46
  5. QDataWidgetMapper & QLabel
    By fpujol in forum Qt Programming
    Replies: 7
    Last Post: 12th November 2007, 12:30

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.