how can I move the pointer in QFileStream to the end of the file?
-
for example I have this file:
**
Hello
**
and anotheer file that I want to copy the file to the end of the first file:
**
world
**
so I want it to be:
**
Hello
world
**
and I open the files
and I did:QFile file("Log_File.txt"); QTextStream stream( &file );
and now I want to move the pointer to the end of the file in order to copy the second file to his end.
how to do it? -
@J-Hilk said in how can I move the pointer in QFileStream to the end of the file?:
file.open(QIODeviceBase::Append | QIODeviceBase::Text);
my program doesnt konw QIODeviceBase- do I have to add include?
-
for example I have this file:
**
Hello
**
and anotheer file that I want to copy the file to the end of the first file:
**
world
**
so I want it to be:
**
Hello
world
**
and I open the files
and I did:QFile file("Log_File.txt"); QTextStream stream( &file );
and now I want to move the pointer to the end of the file in order to copy the second file to his end.
how to do it? -
for example I have this file:
**
Hello
**
and anotheer file that I want to copy the file to the end of the first file:
**
world
**
so I want it to be:
**
Hello
world
**
and I open the files
and I did:QFile file("Log_File.txt"); QTextStream stream( &file );
and now I want to move the pointer to the end of the file in order to copy the second file to his end.
how to do it?@RuWex said in how can I move the pointer in QFileStream to the end of the file?:
and anotheer file that I want to copy the file to the end of the first file:
and now I want to move the pointer to the end of the file in order to copy the second file to his end.
Then you should be opening the first file in append mode, and no "file seeking" by you is required.
-
QFile file("Log_File.txt"); file.open(QIODeviceBase::Append | QIODeviceBase::Text); QTextStream stream( &file );
@J-Hilk said in how can I move the pointer in QFileStream to the end of the file?:
file.open(QIODeviceBase::Append | QIODeviceBase::Text);
my program doesnt konw QIODeviceBase- do I have to add include?
-
@J-Hilk said in how can I move the pointer in QFileStream to the end of the file?:
file.open(QIODeviceBase::Append | QIODeviceBase::Text);
my program doesnt konw QIODeviceBase- do I have to add include?
-
@J-Hilk said in how can I move the pointer in QFileStream to the end of the file?:
file.open(QIODeviceBase::Append | QIODeviceBase::Text);
my program doesnt konw QIODeviceBase- do I have to add include?
-
@RuWex
Why not search the documentation forQIODeviceBase
to find the answer? https://doc.qt.io/qt-6/qiodevicebase.html,#include <QIODevice>
, if#include <QFile>
does not already do so.@JonB said in how can I move the pointer in QFileStream to the end of the file?:
Why not search the documentation for QIODeviceBase to find the answer? https://doc-snapshots.qt.io/qt6-dev/qiodevicebase.html, #include <QIODevice>, if #include <QFile> does not already do so.
I tried to add #include <QIODevice> but it doesnt work:(
-
@JonB said in how can I move the pointer in QFileStream to the end of the file?:
Why not search the documentation for QIODeviceBase to find the answer? https://doc-snapshots.qt.io/qt6-dev/qiodevicebase.html, #include <QIODevice>, if #include <QFile> does not already do so.
I tried to add #include <QIODevice> but it doesnt work:(
-
@RuWex
So tell us what version of Qt you are using, we cannot guess? If it's Qt5 rather than Qt6 it would beQIODevice::...
rather thanQIODeviceBase::...
.
Alternatively did you try @J-Hilk'sQIODevice::Append
/Text
without any extra#include
?