Results 1 to 4 of 4

Thread: Get Column Name from a QSqlQueryModel

  1. #1
    Join Date
    Aug 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Get Column Name from a QSqlQueryModel

    How do you get the name of a column from a QSqlQueryModel if all I have is the index?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get Column Name from a QSqlQueryModel

    You can use QSqlQueryModel::record() or headerData() for this.

  3. #3
    Join Date
    Aug 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Get Column Name from a QSqlQueryModel

    Thanks, I got caught up looking in the wrong place.
    If anyone else ever asks, I used:
    int row = 0;
    int column = 0;
    QString columnName = model->record(row).fieldName(column);

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get Column Name from a QSqlQueryModel

    It's a bit more efficent to use the record() method without parameters, since you don't need a record populated with data:
    Qt Code:
    1. QString columnName = model->record().fieldName( column );
    To copy to clipboard, switch view to plain text mode 
    The version with headerData() looks like this:
    Qt Code:
    1. QString columnName = model->headerData( column, Qt::Horizontal ).toString();
    To copy to clipboard, switch view to plain text mode 
    (although in some cases it might not return the original name of the column).

Similar Threads

  1. QTableView column trouble
    By nategoofs in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2009, 20:14
  2. Replies: 0
    Last Post: 10th November 2006, 13:46
  3. QTable column stretchable with minimum Width
    By sunil.thaha in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2006, 13:17
  4. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00
  5. How to dispay an icon in the first column of QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2006, 15:51

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.