Results 1 to 3 of 3

Thread: To store the Qtablewidget data to .csv or xl file - Issue

  1. #1
    Join Date
    Aug 2015
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default To store the Qtablewidget data to .csv or xl file - Issue

    The following is my piece of code:

    Qt Code:
    1. QString fileName = appData + DIR+ "AISTABLE";
    2. fileName = fileName + d_local.toString("_yyyy-MM-dd") + t_local.toString("_HH-mm-ss") + ".csv";
    3. f_out = fopen(fileName.toAscii().data(), "wb+");
    4. if (f_out == NULL) {
    5. return;
    6. }
    7.  
    8. QString headerString = "d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11\r\n";
    9.  
    10. for(int row = 0;row <ui->tableWidget->rowCount()-1; row++)
    11. {
    12. for(int column = 0;column< ui->tableWidget->columnCount()-1 ;column++)
    13. {
    14. headerString += ui->tableWidget->item(row,column)->text() +",";
    15. }
    16. headerString += "\r\n";
    17. }
    18. fprintf(f_out,"%s",headerString.toAscii().data());
    19. fflush(f_out);
    20. fclose(f_out);
    To copy to clipboard, switch view to plain text mode 

    I have created the Qtablewidget using Qt designer with rows = 300 and column = 12.
    When I execute the above program, I get the following error:

    Unhandled exception at 0x5463d72c in File.exe: 0xC0000005: Access violation reading location 0x00000000.

    What is the problem for not getting output?
    Last edited by anda_skoa; 28th April 2016 at 16:38. Reason: missing [code] tags

  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: To store the Qtablewidget data to .csv or xl file - Issue

    You program crashes, which has nothing to do with "getting output".

    My guess would be that you only have a sparsely populated table and not all item() calls return a valid pointer.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: To store the Qtablewidget data to .csv or xl file - Issue

    Your problem is likely what anda_skoa mentions. But in addition, you are opening the file in binary, not text mode, so what do you expect to get using fprintf? And your code will also stop copying before it reaches the last column of each row as well as the last row of the table. So you need to do a little bit of error checking on the returned QTableWidgetItem pointers as well as your iteration logic.

Similar Threads

  1. QVector to store 3d data
    By Vikram.Saralaya in forum Qt Programming
    Replies: 4
    Last Post: 18th November 2015, 16:01
  2. How to store data in a tablemodel
    By rubikon in forum Newbie
    Replies: 11
    Last Post: 13th August 2012, 14:18
  3. Replies: 2
    Last Post: 15th December 2011, 21:57
  4. Best way to store and retrieve contents of QTableWidget?
    By codeslicer in forum Qt Programming
    Replies: 3
    Last Post: 6th April 2008, 09:39
  5. How to store/get pointer on QTreeWidgetItem data?
    By Teerayoot in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2007, 22:26

Tags for this Thread

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.