Results 1 to 8 of 8

Thread: Mapping two tables on the widgets using QDataWidgetMapper

  1. #1
    Join Date
    Sep 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Mapping two tables on the widgets using QDataWidgetMapper

    Hello,

    There are two tables in SQLite. For a simple example, person and address. How to map data of the current man from both tables to form widgets? How should we synchronize the current index of the two tables, if we use two QDataWidgetMapper's?

    Is there another approach to display related data on the form, including insertion?

    I would be very grateful for your help and examples.

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

    Default Re: Mapping two tables on the widgets using QDataWidgetMapper

    Are you using QSqlRelationalTableModel?
    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
    Sep 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mapping two tables on the widgets using QDataWidgetMapper

    Yes, it is.

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

    Default Re: Mapping two tables on the widgets using QDataWidgetMapper

    So why are you using two widget mappers?
    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
    Sep 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mapping two tables on the widgets using QDataWidgetMapper

    Single mapper can map single table, doesn't it? So I had to use two mappers for both tables. The question is how to synchronize their indexes?

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Mapping two tables on the widgets using QDataWidgetMapper

    Why don't you use an SQL JOIN to make a single result table?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Oct 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Mapping two tables on the widgets using QDataWidgetMapper

    I pretty much have the same issue. I have two tables - a users table and an address table (which contains several necessary fields such as city, state, country etc). The tables are linked via a foreign key (address_id in the users table).

    I'm trying to find a suitable way of setting up this model in QT. However, from my understanding a QSqlRelationalTableModel() won't work here as I don't simply want to replace the foreign key column in the user table with a single column in the address table - I want to replace that foreign key with ALL the columns in the address table.

    Is there a suitable way of doing this or will I have to resort to QSqlQueryModel()?

  8. #8
    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: Mapping two tables on the widgets using QDataWidgetMapper

    If you don't want to use QSqlQueryModel for whatever reason, you can easily create your own QAbstractTableModel derived model which does exactly what you need it to do.

    Cheers,
    _

Similar Threads

  1. mapping composite data from model to widgets
    By tzeentch.gm in forum Newbie
    Replies: 4
    Last Post: 4th October 2011, 06:32
  2. Class for mapping input widgets
    By Hostel in forum Newbie
    Replies: 2
    Last Post: 13th September 2011, 09:21
  3. different column widgets in trees or tables
    By fulbay in forum Qt Programming
    Replies: 1
    Last Post: 6th October 2010, 15:28
  4. Replies: 1
    Last Post: 16th May 2010, 19:25
  5. QDataWidgetMapper to synchronize widgets with QTableView
    By ehamberg in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2008, 20:46

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.