Results 1 to 5 of 5

Thread: QTable - Date Base Problem

  1. #1
    Join Date
    May 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default QTable - Date Base Problem

    Hello,
    I need little help. I am writeing a small library data base using QT Designer. And I got a problem. I don't know how to load data from file to QTable object that I've got on my form. Example file:
    cell_01;cell_02;cell_03;cell_04
    cell_05;cell_06;cell_07;cell_08
    cel1_09;cell_l0;cell_11;cell_12
    cell_13;cell_14;cell_l5;cell_l6
    etc...
    And I want to load this into my QTable object so that will look like that:
    http://img255.imageshack.us/img255/2291/qtra9.jpg

    Please, help me.
    esq

  2. #2
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTable - Date Base Problem

    Please use QTableView and QSqlQueryModel instead. It is very easy to use.

  3. #3
    Join Date
    May 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QTable - Date Base Problem

    The problem is that I can't use QSqlQueryModel at all. I have to build data base without using any SQL librarys which is lame, I know. This is a shool project...

  4. #4
    Join Date
    Jan 2007
    Posts
    68
    Thanks
    9
    Thanked 8 Times in 8 Posts

    Default Re: QTable - Date Base Problem

    just use QTableView & subclass QAbstractTableModel as your model.
    Look here how to do exactly.

    inside your model you can use any kind of datastructure you want:

    Qt Code:
    1. QVariant MyTableModel::data(const QModelIndex &index, int role) const
    2. {
    3. if (!index.isValid())
    4. return QVariant();
    5.  
    6. if (role == Qt::TextAlignmentRole)
    7. {
    8. return int(Qt::AlignRight | Qt::AlignVCenter);
    9. }
    10. else if(role == Qt::ToolTipRole)
    11. {
    12. return "hello"; // for example
    13. }
    14. else if (role == Qt::DisplayRole)
    15. {
    16. return myData[index.row()][index.column()]; // for example
    17. }
    18. return QVariant();
    19. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    May 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QTable - Date Base Problem

    sry, I didn't mention that I'm writing in qt3, but tnx so much!

Similar Threads

  1. Replies: 7
    Last Post: 15th April 2007, 02:39
  2. QTable resize problem with large tables
    By Robzzz in forum Newbie
    Replies: 3
    Last Post: 22nd May 2006, 15:13
  3. Problem with QTable
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 11:00

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.