Results 1 to 2 of 2

Thread: Loading csv data to tablewideget (I am completely stuck!)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Loading csv data to tablewideget (I am completely stuck!)

    Hello guys,

    I am very new to Qt. Trying to load csv data to my simple tablewideget. Here is

    Data.csv:
    John Kl;34;1335532;CA;0444344
    Kuma jo;54;44432;NY;0322355
    Lebal ho;24;44022;NY;0110004
    Here is what i am trying:
    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QTableWidget>
    4. #include <QTableWidgetItem>
    5. #include <QFile>
    6. #include <QString>
    7. #include <QStringList>
    8. #include <QMessageBox>
    9. #include <QTextStream>
    10. #include <QDebug>
    11.  
    12. int main(int argc, char **argv)
    13. {
    14. QApplication app(argc, argv);
    15. QMainWindow *window = new QMainWindow();
    16.  
    17. QFile file("Data.txt");
    18. if(!file.open(QIODevice::ReadOnly))
    19. msg.information(0,"Error!","Error opening file!",0);
    20.  
    21. QTextStream in(&file);
    22. QStringList loadCsv;
    23.  
    24. QTableWidget *myTable=new QTableWidget();
    25.  
    26.  
    27.  
    28. while(!file.atEnd()){
    29.  
    30. loadCsv<<in.readLine().split(";");
    31.  
    32. myTable->setColumnCount(loadCsv.size());
    33. for(int row=0;row<in.readLine().size();++row){
    34. myTable->setRowCount(loadCsv.size()); //It reading only first line.
    35. for(int col=0;col<loadCsv.size();++col){
    36.  
    37. myTable->setColumnCount(loadCsv.size());
    38. QTableWidgetItem *Items= new QTableWidgetItem(loadCsv[col]);
    39. myTable->setItem(row,col,Items);
    40.  
    41. }
    42. }
    43. }
    44. qDebug()<<loadCsv;
    45. window->setCentralWidget(myTable);
    46. window->show();
    47. return app.exec();
    48. }
    To copy to clipboard, switch view to plain text mode 
    I know this code is not okay as it is not working at all and i don't know how to fix it, I guess i am doing something wrong with the loop. but I just don't get an easy way to make this work. If someone can help me to load the csv to load in the QTableWideget then it will be a greate resource for me to study.
    Last edited by qtgraphical; 24th August 2013 at 19:37. Reason: updated contents

Similar Threads

  1. Asynchronous loading from HTTP (as data stream)
    By shestero in forum Qt Programming
    Replies: 0
    Last Post: 21st October 2012, 10:45
  2. Slow loading of data into QTableWidget
    By KenJustKen in forum Qt Programming
    Replies: 5
    Last Post: 11th April 2012, 15:50
  3. Replies: 5
    Last Post: 2nd April 2011, 12:03
  4. Loading data in a thread
    By Cruz in forum Qt Programming
    Replies: 23
    Last Post: 28th October 2010, 17:18
  5. Loading a QPixmap from raw data
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2008, 10:12

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.