Results 1 to 2 of 2

Thread: Add a Non DB column, to SqlTableModel, for External Data.

  1. #1
    Join Date
    Feb 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Add a Non DB column, to SqlTableModel, for External Data.

    what i need is to add a extra column to a QSqlTableModel built from a Select query , to hold data that is not in the DataBase. to be displayied, in a table format on a QT screen , so
    QT Version 4.7.1 (Operating System - XP sp3)
    DB : MYsql
    Table i require is
    Column 1 = ID, (from select query)
    Column 2 = GallyUNC (from select query)
    Column 3 = Image (held on another server, NOT in Database)
    I Have tried this,
    1.
    model->insertColumn(2);
    model->setHeaderData(2,Qt::Horizontal,"Image",Qt:isplayRole);
    Which results in the following debug output , so it has added something to SqlTableModel

    0:" QSqlField("Id", qlonglong, length: 20, precision: 0, required: no, generated: yes, typeID: 8) "140507771740"
    " 1:" QSqlField("GalleryUNC", QString, length: 300, precision: 0, required: no, generated: yes, typeID: 253) "dddd"
    " 2:" QSqlField("", , generated: no) ""
    2. Also this.
    QSqlField field("Image",QVariant::String);
    field.setName("Image");
    field.setGenerated(true);
    field.setReadOnly(false);
    field.setLength(300);
    field.setType(QVariant::String);
    field.setPrecision(0);
    field.setRequired(false);
    field.setValue("imagef");
    for (int ix = 0 ; ix < model->rowCount() ; ++ix)
    {
    model->record(ix).append(field);
    qDebug() << model->record(ix);
    }
    }
    But nothing seems to be working, so has any one got any ideas where i am going wrong, or examples, that can point me in the right direction. to merge DB data with none DB data and display it.

  2. #2
    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: Add a Non DB column, to SqlTableModel, for External Data.

    Why don't you use a custom QSortFilterProxyModel to interface between your SQL model and the view? Override the columnCount() and data() methods to add your extra column and to supply the data for it, and make sure that the filterAccepts...() methods return the right answers.

Similar Threads

  1. How to fill an inserted column with data?
    By croo in forum Qt Programming
    Replies: 3
    Last Post: 12th December 2010, 20:58
  2. How to get all column data on row clicked
    By wirasto in forum Qt Programming
    Replies: 7
    Last Post: 9th November 2009, 06:21
  3. Replies: 6
    Last Post: 6th August 2009, 18:18
  4. SqlTableModel not updating AbstractProxyModel
    By akiross in forum Qt Programming
    Replies: 7
    Last Post: 13th November 2008, 17:51
  5. extract data from sqlTablemodel
    By peace_comp in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2008, 20:25

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.