Results 1 to 4 of 4

Thread: MODEL/VIEW programming

  1. #1
    Join Date
    Apr 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default MODEL/VIEW programming

    Hi all,
    Can some help me with MODEL/VIEW programming in QT4
    I have program for database of humans, and i display small table with katalog of peoples,
    I used on this Q3Tab in new widget, and my katalog is stored in container „vector“…
    here is link screen my pgm


    void MainWindow::show_table()
    {
    Tab *tabulka = new Tab;
    tabulka->table->setNumRows(people.size());
    tabulka->table->setColumnWidth ( 0, 115 );
    tabulka->table->setColumnWidth ( 1, 115 );
    tabulka->table->setColumnWidth ( 2, 70 );

    for( int row= 0; row < people.size() ; row++)
    {
    tabulka->table->setText(row,0,people[row].surname);
    tabulka->table->setText(row,1,people[row].first_name);
    tabulka->table->setText(row,2,people[row].number);
    tabulka->table->sortColumn(0,TRUE,TRUE);
    }
    tabulka->table->setReadOnly(TRUE);
    tabulka->show();
    }


    „people“ is container style vector..
    But i have to show this my table via MODEL/VIEW programming,
    I readed qt-Assistant but i dont know still, how i can make it, pls help me with this
    and sory for my bad english

  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: MODEL/VIEW programming

    Hello!

    Do you use some kind of SQL database to store the info?

    You might want to take a look at Qt examples about model-view programming and reference for classes like QTableView, QAbstractItemModel and QSqlTableModel.

    If you have any doubts, feel free to ask.

  3. #3
    Join Date
    Apr 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: MODEL/VIEW programming

    @wysota
    I didnt use some kind of SQL database, i stored data into ordinary *.txt file, but i mean that this in not important!!!
    I have stored data in program in vector container (from C++) hier it is names "people".
    I readed assistant with examples here model/view programming, but no one directly working with table. maybe this "chart"
    my general problem is that i have table in new widget, not in mainwidow pgm

  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: MODEL/VIEW programming

    Quote Originally Posted by mira
    I didnt use some kind of SQL database, i stored data into ordinary *.txt file, but i mean that this in not important!!!
    It is important, because if you used SQL, you could use one of existing sql-based models Qt4 provides.

    I have stored data in program in vector container (from C++) hier it is names "people".
    I readed assistant with examples here model/view programming, but no one directly working with table. maybe this "chart"
    my general problem is that i have table in new widget, not in mainwidow pgm
    If your model is simple, you can subclass QStandardItemModel (or use it directly). And then just set the model to QTableView and you're done. If your model is complex you should subclass QAbstractTableModel.

Similar Threads

  1. A question about Model/View programming
    By awhite1159 in forum Qt Programming
    Replies: 5
    Last Post: 15th June 2008, 15:38
  2. quick question on model/view programming
    By locus in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2007, 10:04
  3. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04
  4. MODEL/VIEW programming and TABLES
    By newbie in forum Qt Programming
    Replies: 5
    Last Post: 27th August 2006, 21:26
  5. Replies: 2
    Last Post: 16th February 2006, 19:09

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.