Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 11

Qt-interest Archive, March 2002
Write at end of File


Message 1 in thread

I have a file with one word of text on each line. I want to open the file and 
add a new line of text at the end of the file. How would I do this.

This is the code that I am using to open the file:
QFile filename("myfile");
	if(filename.open(IO_ReadWrite) )
	{
		QTextStream writestring (&filename);
	}
		
	algorithmlist.close();

I know the atEnd function shows when the end of the file is reached. How can 
I add a new line of text at the end of the file?

Thanks, Mark


Message 2 in thread

If you do it with QFile?

QFile filename("myfile");
filename.open(IO_ReadWrite);

int file_size = filename.size();
if(filename.at(file_size))
{
	// write the line
}

Nicolas

-----Original Message-----
From: owner-qt-interest@trolltech.com
[mailto:owner-qt-interest@trolltech.com] On Behalf Of Mark Finlay
Sent: Sonntag, 31. März 2002 15:11
To: qt-interest@trolltech.com
Subject: Write at end of File

I have a file with one word of text on each line. I want to open the
file and 
add a new line of text at the end of the file. How would I do this.

This is the code that I am using to open the file:
QFile filename("myfile");
	if(filename.open(IO_ReadWrite) )
	{
		QTextStream writestring (&filename);
	}
		
	algorithmlist.close();

I know the atEnd function shows when the end of the file is reached. How
can 
I add a new line of text at the end of the file?

Thanks, Mark

--
 [ signature omitted ] 

Message 3 in thread

Hi,

you should open the file in append mode:

QFile f("myfile");
if (f.open(IO_WriteOnly | IO_Append))
{
    QTextStream s(&f);
    s << "this text will be appended" << endl;
    f.close();
}

Bye,
Bernd

On Sunday 31 March 2002 15:11, Mark Finlay wrote:
> I have a file with one word of text on each line. I want to open the
> file and add a new line of text at the end of the file. How would I do
> this.


Message 4 in thread

Mark Finlay <9839143@student.ul.ie> wrote:
>I have a file with one word of text on each line. I want to open the file and
>add a new line of text at the end of the file. How would I do this.
>
>This is the code that I am using to open the file:
>QFile filename("myfile");
>       if(filename.open(IO_ReadWrite) )
>       {
>               QTextStream writestring (&filename);
>       }
>
>       algorithmlist.close();
>
>I know the atEnd function shows when the end of the file is reached. How can
>I add a new line of text at the end of the file?

Take at look at IO_Append in the documentation for QFile::open. I think 
you'll find that open( IO_ReadWrite | IO_Appand ) provides what you are 
looking for.

-- 
 [ signature omitted ]