PDA

View Full Version : Storing a QTextStream in a container



quimnuss
24th July 2017, 16:00
Hello everyone,

I have a vector of simple structs[1] that I have to write into several txt depending of the datamember _datatype_. I'll call this vector the structvector.

To do this I've thought I'll open a QTextStream for each file and then traverse the structvector and write to the correspondant stream.

Since the number of datatypes is not known (althought <= 6), I've thought I'd store each stream on a container.

The problem is, I can't find a way to correctly store and manage a QTextStream memory. I've tried with a map and vector using different types T:
unique_ptr<QTextStream>,
QTextStream* = new QTextStream and
QTextStream. The first complains with "cannot delete incomplete type", the second segfaults on the delete and the latter complains that Copy is private on QTextStream.

Hoe am I supposed to store QTextStreams in a container? Would you approach this differently?


[1] { QString datatype; int count; double timestamp; }

high_flyer
24th July 2017, 16:25
your problem clearly has nothing to do with the issue at hand but with basic C++ syntax, and with it probably C++ in general.
All of the code snippets you posted show that you are not aware that you need a *variable* declared of the type you want.

I assume that the three code snippets are a try to make a QTextSream object a member of a class? I am can only guess as you gave no further details.


unique_ptr<QTextStream> uniqueStream(new QTextStream());




QTextStream* pTextStream = new QTextStream();




QTextStream textStream;


Please read the QTextStream docs, there are some code snippets there to help you out.
http://doc.qt.io/qt-5/qtextstream.html


oe am I supposed to store QTextStreams in a container? Would you approach this differently?
No need to store the stream anywhere.
Simply have a function or a method that takes a struct and the destination as parameters, and in it use a stream to stream you struct.

However, all I did here was to give you a fish. (if at all)
It is very probable you will get stuck at the next trivial problem.
You really fist should learn some basic C++, and then return to this problem.