Results 1 to 2 of 2

Thread: Storing a QTextStream in a container

  1. #1
    Join Date
    Jul 2015
    Posts
    52
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Storing a QTextStream in a container

    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:
    Qt Code:
    1. unique_ptr<QTextStream>
    To copy to clipboard, switch view to plain text mode 
    ,
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    . 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; }

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Storing a QTextStream in a container

    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.
    Qt Code:
    1. unique_ptr<QTextStream> uniqueStream(new QTextStream());
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QTextStream* pTextStream = new QTextStream();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QTextStream textStream;
    To copy to clipboard, switch view to plain text mode 

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Storing A hex value as a string?
    By Splatify in forum Newbie
    Replies: 4
    Last Post: 7th February 2011, 06:26
  2. Flag storing
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2009, 05:26
  3. Storing widget state
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 10th April 2008, 09:55
  4. Quick ? about qSort(Container & container)
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2007, 11:20
  5. storing captions
    By vijay anandh in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 07:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.