PDA

View Full Version : Problem in Filling the qtablewidget Using file ...help me!!:)



dajas
17th June 2013, 06:43
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:


QFile smstr1("semester1.txt");
if (!smstr1.open(QIODevice::ReadOnly|QIODevice::Text) )
return;

QTextStream t1(&smstr1);
int k=1;
while (!t1.atEnd() && k<=(ui->tableWidget->rowCount()*ui->tableWidget->columnCount()))
{

if (k==1)
{
ui->tableWidget->item(0,0)->setText(t1.readLine());k++;
}

else if (k==2)
{
ui->tableWidget->item(1,0)->setText(t1.readLine());k++;
}

else if (k==3)
{
ui->tableWidget->item(2,0)->setText(t1.readLine());k++;
}

else if (k==4)
{
ui->tableWidget->item(3,0)->setText(t1.readLine());k++;
}

else if (k==5)
{
ui->tableWidget->item(4,0)->setText(t1.readLine());k++;
}
else if (k==6)
{
ui->tableWidget->item(5,0)->setText(t1.readLine());k++;
}
else if (k==7)
{
ui->tableWidget->item(0,1)->setText(t1.readLine());k++;
}
else if (k==8)
{
ui->tableWidget->item(1,1)->setText(t1.readLine());k++;
}
else if (k==9)
{
ui->tableWidget->item(2,1)->setText(t1.readLine());k++;
}

else if (k==10)
{
ui->tableWidget->item(3,1)->setText(t1.readLine());k++;
}
else if (k==11)
{
ui->tableWidget->item(4,1)->setText(t1.readLine());k++;
}
else if (k==12)
{
ui->tableWidget->item(5,1)->setText(t1.readLine());k++;
}
else if (k==13)
{
ui->tableWidget->item(0,2)->setText(t1.readLine());k++;
}
else if (k==14)
{
ui->tableWidget->item(1,2)->setText(t1.readLine());k++;
}
else if (k==15)
{
ui->tableWidget->item(2,2)->setText(t1.readLine());k++;
}
else if (k==16)
{
ui->tableWidget->item(3,2)->setText(t1.readLine());k++;
}
else if (k==17)
{
ui->tableWidget->item(4,2)->setText(t1.readLine());k++;
}
else if (k==18)
{
ui->tableWidget->item(5,2)->setText(t1.readLine());k++;
}


}


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 ;)

Lesiok
17th June 2013, 07:21
What it means "it doesn't work" and what is "Runtime error" ?

dajas
17th June 2013, 07:27
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 !!

Lesiok
17th June 2013, 10:47
So run program under debuger and try to find the reason for this behavior. The glass ball today is not working.