Missing items in loadFile
Hello anyone,
I want to load my contact.txt in the function loadFile.
In my contact.txt i have seperated the items through tab.
When open the file for reading he display only in QTreeWidget 4 items
example:
Drabo Hardenberg Dhr. J. Tuik 0523-678905.
See code loadFile
Code:
void MainWindow
::loadFile(const QString &fileName
) {
if( !file.
open(QFile::ReadOnly)) return;
do {
line = in.readLine();
if(!line.isEmpty())
{
if(it != contact.end())
{
item->setText(0, (*it));
++it;
}
if(it != contact.end())
{
item->setText(1, (*it));
++it;
}
if(it != contact.end())
{
item->setText(2, (*it));
++it;
}
if(it != contact.end())
{
item->setText(3, (*it));
++it;
}
}
}while(!line.isEmpty());
file.close();
}
Is there something missing in the code
Here is my code for the saveFile
Code:
void MainWindow
::saveFile(const QString &fileName
) {
if ( !file.
open(QFile::WriteOnly)) return;
int ind = 0;
for ( unsigned int i = 0; i < 4; i++ )
out << item->text(i) << '\t';
out << '\n';
ind ++;
}
file.close();
}
Re: Missing items in loadFile
Hi,
What is the exact problem...you want to display all the Items (If I count well, there are 6 "items" in the example you gave... ?
Guilugi.
Re: Missing items in loadFile
seems like you only save 4 items to your file.
Code:
for ( unsigned int i = 0; i < 4; i++ )
what is in your file after using safeFile? All the fields or just 4 of them?
cheers
Re: Missing items in loadFile
In my contact.txt there are 4 items on each line seperate with a tab
example of my contact.txt.
Drabo Hardenberg Dhr. J. Tuik 0523-456789
KMS Hardenberg Dhr. Kamphuis 0523-890567
GMS Hardenberg Dhr. Huisman 0523-678945
When i load the contact.txt the QTreeWidget display 1 line with items and not 3 lines.
Re: Missing items in loadFile
Ok,
The fact is you create only one TreeWidgetItem!
You have to put your line in the loop, like this :
Code:
void MainWindow
::loadFile(const QString &fileName
) {
if( !file.
open(QFile::ReadOnly)) return;
do {
line = in.readLine();
if(!line.isEmpty())
{
....
This should work better :)
Guilugi.
Re: Missing items in loadFile
you could try :
!in.atEnd()}
instead of
!line.isEmpty());
Re: Missing items in loadFile
Thanks guilugi for your answer and time it works fine now.
Everall i have also tested your sugestion but it didn't work.
Thanks also for your sugestion.
Bye