Results 1 to 4 of 4

Thread: Problem in Filling the qtablewidget Using file ...help me!!:)

  1. #1
    Join Date
    Jun 2013
    Location
    somewhere
    Posts
    2
    Qt products
    Qt5

    Question Problem in Filling the qtablewidget Using file ...help me!!:)

    hi everyone,
    i am new in qt and i've worked with for recently week !
    i've written a txt file and wanna fill the qtablewidget from the datas on the txt file(named semester1)
    this is my code , i think my alghoritm is right but ... so it doesn't work ! with a Runtime error !! could you please help me ?!
    this is my code:
    Qt Code:
    1. QFile smstr1("semester1.txt");
    2. if (!smstr1.open(QIODevice::ReadOnly|QIODevice::Text))
    3. return;
    4.  
    5. QTextStream t1(&smstr1);
    6. int k=1;
    7. while (!t1.atEnd() && k<=(ui->tableWidget->rowCount()*ui->tableWidget->columnCount()))
    8. {
    9.  
    10. if (k==1)
    11. {
    12. ui->tableWidget->item(0,0)->setText(t1.readLine());k++;
    13. }
    14.  
    15. else if (k==2)
    16. {
    17. ui->tableWidget->item(1,0)->setText(t1.readLine());k++;
    18. }
    19.  
    20. else if (k==3)
    21. {
    22. ui->tableWidget->item(2,0)->setText(t1.readLine());k++;
    23. }
    24.  
    25. else if (k==4)
    26. {
    27. ui->tableWidget->item(3,0)->setText(t1.readLine());k++;
    28. }
    29.  
    30. else if (k==5)
    31. {
    32. ui->tableWidget->item(4,0)->setText(t1.readLine());k++;
    33. }
    34. else if (k==6)
    35. {
    36. ui->tableWidget->item(5,0)->setText(t1.readLine());k++;
    37. }
    38. else if (k==7)
    39. {
    40. ui->tableWidget->item(0,1)->setText(t1.readLine());k++;
    41. }
    42. else if (k==8)
    43. {
    44. ui->tableWidget->item(1,1)->setText(t1.readLine());k++;
    45. }
    46. else if (k==9)
    47. {
    48. ui->tableWidget->item(2,1)->setText(t1.readLine());k++;
    49. }
    50.  
    51. else if (k==10)
    52. {
    53. ui->tableWidget->item(3,1)->setText(t1.readLine());k++;
    54. }
    55. else if (k==11)
    56. {
    57. ui->tableWidget->item(4,1)->setText(t1.readLine());k++;
    58. }
    59. else if (k==12)
    60. {
    61. ui->tableWidget->item(5,1)->setText(t1.readLine());k++;
    62. }
    63. else if (k==13)
    64. {
    65. ui->tableWidget->item(0,2)->setText(t1.readLine());k++;
    66. }
    67. else if (k==14)
    68. {
    69. ui->tableWidget->item(1,2)->setText(t1.readLine());k++;
    70. }
    71. else if (k==15)
    72. {
    73. ui->tableWidget->item(2,2)->setText(t1.readLine());k++;
    74. }
    75. else if (k==16)
    76. {
    77. ui->tableWidget->item(3,2)->setText(t1.readLine());k++;
    78. }
    79. else if (k==17)
    80. {
    81. ui->tableWidget->item(4,2)->setText(t1.readLine());k++;
    82. }
    83. else if (k==18)
    84. {
    85. ui->tableWidget->item(5,2)->setText(t1.readLine());k++;
    86. }
    87.  
    88.  
    89. }
    To copy to clipboard, switch view to plain text mode 

    consider : "k" shows the line of the txt file , i mean each tablewidget has 6 rows with 3 columns ... so my file has 18 lines .
    Thanx in Advance
    Last edited by dajas; 17th June 2013 at 06:29.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,499
    Thanked 277 Times in 272 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in Filling the qtablewidget Using file ...help me!!:)

    What it means "it doesn't work" and what is "Runtime error" ?

  3. #3
    Join Date
    Jun 2013
    Location
    somewhere
    Posts
    2
    Qt products
    Qt5

    Default Re: Problem in Filling the qtablewidget Using file ...help me!!:)

    Lesiok ... thanks for your rep
    i mean i run the program successfully and when i push a button (to fill the table using file ) , it opens a new window and exit the Program !!
    Last edited by dajas; 17th June 2013 at 06:31.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,499
    Thanked 277 Times in 272 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in Filling the qtablewidget Using file ...help me!!:)

    So run program under debuger and try to find the reason for this behavior. The glass ball today is not working.

Similar Threads

  1. problem filling a QtableWidget
    By mmm286 in forum Newbie
    Replies: 3
    Last Post: 27th May 2010, 08:31
  2. Filling empty cells in QTableWidget
    By lyucs in forum Newbie
    Replies: 2
    Last Post: 20th October 2009, 17:12
  3. Filling a QGraphicsItem
    By c_srikanth1984 in forum Qt Programming
    Replies: 15
    Last Post: 6th July 2009, 14:34
  4. Filling an image
    By Caius Aérobus in forum Qt Programming
    Replies: 6
    Last Post: 6th July 2008, 21:13
  5. filling scrollview
    By illuzioner in forum Qt Programming
    Replies: 1
    Last Post: 17th February 2006, 22:00

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.