Results 1 to 2 of 2

Thread: SQL Query + ListView

  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default SQL Query + ListView

    Qt Code:
    1. if(db.open()){
    2.  
    3. QSqlDatabase db = QSqlDatabase::database("maindb");
    4. QSqlQuery query(db);
    5.  
    6. query.exec("SELECT `Name` FROM `dictionarystrings` WHERE `LanguageID` = '1'");
    7.  
    8. while (query.next()){
    9. QString nameString = query.value(0).toString();
    10. QStandardItem* item = new QStandardItem(nameString);
    11. item->setEditable(false);
    12. item->setCheckable(false);
    13. item->setSizeHint(QSize(345,42));
    14.  
    15. model->setItem(nameString, item);
    16.  
    17. }
    18.  
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    unsure exactly how to display the contents of my query in a listview i have on the gui ui.view


    sorry i have learned more about coding with QT when asking for help and searching forums than i have watching video tutorials

    thanks for all your help !!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: SQL Query + ListView

    See QSqlQueryModel and use QListView::setModel(). And also try to read the documentation of Qt. It is really good and comes with a lot of examples.

Similar Threads

  1. ListView not displayed
    By Globulus in forum Newbie
    Replies: 0
    Last Post: 21st August 2011, 08:59
  2. qml listview
    By Le_B in forum Qt Quick
    Replies: 1
    Last Post: 25th May 2011, 13:01
  3. how do you reload a listView?
    By implor in forum Newbie
    Replies: 5
    Last Post: 16th May 2010, 22:21
  4. listview
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 12:05
  5. ListView and CurrentChanged
    By kroenecker in forum Newbie
    Replies: 13
    Last Post: 24th March 2007, 02:35

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
  •  
Qt is a trademark of The Qt Company.