Results 1 to 4 of 4

Thread: Any Qt support for building strings from lists?

  1. #1
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Any Qt support for building strings from lists?

    Hi,
    I have a QList<QPointF> type object. I'd like to make a string out of it with commas between the string representations of the points. I wonder if there is a convenience method for this which avoids wasteful allocation of memory.

    In C# there was a StringBuilder, if I recall right. I'm looking for something analogous.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Any Qt support for building strings from lists?

    QTextStream

  3. #3
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Any Qt support for building strings from lists?

    Hi,
    The following code seems to work,

    Qt Code:
    1. QString aString;
    2. QTextStream out(&aString,QIODevice::WriteOnly);
    3. out << 1;
    4. out << "+";
    5. out << 2;
    6. // and so on...
    7. qDebug()<<aString;
    To copy to clipboard, switch view to plain text mode 
    But I'd have to be convinced that it doesn't keep on concatenating and reallocating wastefully
    Thanks anyway.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Any Qt support for building strings from lists?

    If you want to have a string then you have to allocate as much memory as needed to hold the string. If you just want to store the textual representation somewhere then you can use QTextStream as alreay suggested to save pieces of your text to a file. But regardless if you use the text stream or not, you'll have to create those pieces of text yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to Building Qt with OpenSSL support using the Windows SDK
    By josecarlosmissias in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2011, 06:48
  2. Building Qt with SSL Support
    By plucas in forum Installation and Deployment
    Replies: 4
    Last Post: 13th July 2009, 15:44
  3. Some problems with lists
    By gdiepen in forum Qt Programming
    Replies: 9
    Last Post: 16th January 2008, 16:54
  4. When sort the lists?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 14th April 2006, 16:30
  5. Problem building Qt4.1.0 with thread support on windows XP
    By pavithra in forum Installation and Deployment
    Replies: 1
    Last Post: 1st April 2006, 11:35

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.