Results 1 to 2 of 2

Thread: Outputting to a .txt file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Outputting to a .txt file

    Hey,

    How do I output to a .txt file without getting all of those weird symbols?? The program I'm making will generate a file which is NOT .txt format, but I want it to be ledgible if someone decides to open it in .txt format. Let me show you the code before I explain (it's really messy):

    Qt Code:
    1. QDataStream out(&file);
    2. out.setVersion(QDataStream::Qt_4_5);
    3. out << "Name\tType\t\ttotalarea\tDimx\t\tDimy\t\tNbcells\t\tNbLayers\tLayer#\tLayer%\tLayerArea"
    4. "\tNb\tMeannucleararea\t\tstdvnucleararea\t\tNb\tMeancellarea\tstdvcellarea\tNb\tMeanNC\t"
    5. "stdvNC\tNb\tMeanMeanRadius\tstdvMeanRadius\tNb\tMeanMaxRadius\tstdvMaxRadius\tNb\tMeanSpericity"
    6. "\tstdvSphericity\tNbPolygons\tmeanPolyarea\tstdvpolyarea\tNbdist\tmeandist\tstdvdis\n";
    7. for(int i = 0; i < allData.size(); i++)
    8. out << "0" << "0" << "0.0" << ui.xSpinBox->value() << ui.ySpinBox->value() << ui.doubleSpinBox->value()
    9. << ui.layerList->count() << i << "0.0" << ui.doubleSpinBox_2->value()
    10. << "0\t0.0\t0.0\t0\t0.0\t0.0\t0\t0.0\t0.0\t0\t0.0\t0.0\t0" << ui.doubleSpinBox_3->value()
    11. << ui.doubleSpinBox_4 << "0\t0.0\t0.0" << ui.doubleSpinBox_5->value() << "0.0\t0.0\t0\t0.0\t0.0\n";
    To copy to clipboard, switch view to plain text mode 

    So lines 3-6 will essentially be columns headers in the text file, while lines 7-11 should print out some predetermined values (the zeros), and also some other values that are determined during runtime (ie the spinBox values). Although the zeros do get printed, the spinBox values do not, AND the data is all printed onto one line in the .txt file, making it hard to decipher. What can I do to fix this?

    PS Is there also a shortcut to avoid having to type '\t' after every word?

    Thanks!

    EDIT: I figured out how to make the file the way I want, the only question that I still have is what is the syntax for a new line? '\n' isn't working.
    Last edited by bbad68; 23rd January 2010 at 01:11.

Similar Threads

  1. qmake outputting wrong kind of makefile...
    By andy.fillebrown in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2009, 16:37
  2. Replies: 1
    Last Post: 5th June 2009, 08:10
  3. Replies: 3
    Last Post: 28th March 2009, 15:37
  4. Replies: 3
    Last Post: 25th May 2007, 07:49
  5. Outputting text
    By kroenecker in forum Newbie
    Replies: 5
    Last Post: 13th January 2006, 11:08

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
  •  
Qt is a trademark of The Qt Company.