Results 1 to 2 of 2

Thread: Listing a column of a table to a QListWidget

  1. #1
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Listing a column of a table to a QListWidget

    Hi! I have a SQLite database with a table names monitored_directories. I would like to list the column original_path of this table in a QListWidget, where I can then edit the elements to upgrade my database. After reading documentation and examples I came up with this:

    Qt Code:
    1. tableModel = new QSqlRelationalTableModel(this, LBTGlobals::getInstance()->dbManager->db);
    2. tableModel->setTable("monitored_directories");
    3. tableModel->select();
    4. mapper = new QDataWidgetMapper(this);
    5. mapper->setModel(tableModel);
    6. mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    7. mapper->addMapping(listDir, tableModel->fieldIndex("original_path"));
    8. mapper->toFirst();
    To copy to clipboard, switch view to plain text mode 

    The QListWidet listDir is empty, event if I have records in the table. What am I doing wrong?
    Thanks for any advice!

  2. #2
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Listing a column of a table to a QListWidget

    Appearantly, almost everything was wrong This is how I did it:
    Qt Code:
    1. tableModel = new QSqlTableModel(this, LBTGlobals::getInstance()->dbManager->db);
    2. tableModel->setTable("monitored_directories");
    3. tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    4. tableModel->select();
    5. listDir->setModel(tableModel);
    6. listDir->setModelColumn(1);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Column/Row no of ComboBox Widget in Table
    By ankurjain in forum Qt Programming
    Replies: 13
    Last Post: 6th December 2011, 12:03
  2. QListwidget with checkbox compare sql table
    By damodharan in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2010, 12:35
  3. Replies: 5
    Last Post: 26th April 2010, 07:59
  4. Table Column Problem
    By kenny_isles in forum Newbie
    Replies: 1
    Last Post: 6th March 2007, 00:35
  5. Replies: 1
    Last Post: 24th August 2006, 12:44

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.