Results 1 to 4 of 4

Thread: Load text file to tableview

  1. #1
    Join Date
    May 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Load text file to tableview

    Hello everyone,

    I have a problem with loading the data from the file into the control tableview. For now, I created a function that has to load data from a file.
    Qt Code:
    1. void example::load(const QString &file)
    2. {
    3. QString p(":/folder/file/");
    4.  
    5.  
    6. p+=file;
    7. QFile filein(p);
    8. if (!filein.open(QFile::ReadOnly))
    9. qDebug(Error couldn't open file: %s",qPrintable(file));
    10. double p1;
    11.  
    12. QTextStream stream(&filein);
    13. while (!filein.atEnd())
    14. {
    15. stream>>p1;
    16.  
    17. }
    18. stream.readLine() ;
    19. }
    To copy to clipboard, switch view to plain text mode 
    Tableview indicator added to the form, and now i want the data to be loaded when you start the application.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Load text file to tableview

    Easiest way is to populate a QStandardItemModel with your data and then set this as the model on the view.

    Cheers,
    _

  3. #3
    Join Date
    May 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Load text file to tableview

    You can give an example of such a table?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Load text file to tableview

    The documentation for QStandardItemModel has one.

    Cheers,
    _

Similar Threads

  1. Can Qwebview load xml/xsl file?
    By richardander in forum Qt Programming
    Replies: 3
    Last Post: 26th August 2015, 22:36
  2. How to export data in tableview to an excel file?
    By drunknight in forum Qt Programming
    Replies: 2
    Last Post: 31st December 2013, 02:39
  3. How to get text for Tableview to Combobox ?
    By hohoanganh205 in forum Newbie
    Replies: 1
    Last Post: 26th December 2011, 10:54
  4. Replies: 15
    Last Post: 15th March 2011, 15:34
  5. Replies: 1
    Last Post: 3rd September 2008, 14:16

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.