Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7726213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:09:30+00:00 2026-06-01T05:09:30+00:00

I am a student programmer using QT to develop and application for work. Currently

  • 0

I am a student programmer using QT to develop and application for work. Currently I am developing the save functions in which data is taken from a table and saved to a file. Im running into some trouble when I try to write the data into columns. Not to confuse anyone; my problem is formatting text WHEN SAVING from the data table; not reading into it. So currently when data is saved from my Table it is saved into a file and looks like this:

0 0.048 300 101325 0 0
10 0.048 300 101325 0 0

I need it to look like this

0  0.048 300 101325 0 0
10 0.048 300 101325 0 0

During research I came across setw from the iomanip library in c++ which sets a minimum amount of characters to fill data into and then uses the rest as padding. Sounds perfect right? Problem is I cant get it to work with anything besides cout; which isn’t what I need it for. I need it to basically append spaces to my string prior to being written out.

I also feel like Qt should probably have something to help me accomplish what I need here(alot easier). I just cant seem to find this member function after refencing QString documentation, QStringList Doucmentation, and most of all QTextStream Documentation.

Currently my save function looks like this:

QTextStream data(&saveFileAsscf);
QStringList tmpList;
for (int x = 0; x<ui->tableWidgetReaderTable->rowCount(); x++)
                {
                    strList.clear();
                    for(int a = 0; a < ui->tableWidgetReaderTable->columnCount(); a++)
                    {
                        strList << ui->tableWidgetReaderTable->item(x,a)->text();
                    }
                    data <<strList.join(" ") << "\n";
                }

I am so sure that setFieldWidth is my answer from the QTextStream Documentation. but I cant get it to work right.
Tried:

data.setFieldWidth(13) << strList.join(" ") << "\n";

I’m hoping that this is an easy answer for someone and I’m just running into some writers block but any help would be apperciated in accomplishing this. Thanks for reading my post and I appreciate any help contributed to bridge the gap here!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:09:31+00:00Added an answer on June 1, 2026 at 5:09 am

    std::fstream is one option if you want to use STL. However if you’re treating the entire string list as a field you’re width is far more than 13 by the example output given you could try setFieldWidth(23) but it will probably pad the end. If you instead treat each value as a field then it becomes easier.

    Example of what I mean by treating each value as a field:

    QTextStream data(&saveFileAsscf);
    for (int x = 0; x<ui->tableWidgetReaderTable->rowCount(); x++)
    {
       data.setPadChar(' ');
       for(int a = 0; a < ui->tableWidgetReaderTable->columnCount(); a++)
       {
          QString value = ui->tableWidgetReaderTable->item(x,a)->text();
          data.setFieldWidth(qMax(2, value.length()));
          data << value;
          data.setFieldWidth(1);
          data << " ";
       }
       data << "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a student programmer using Qt to develop a GUI application. I am
Im a student programmer using Qt to develop a GUI for work and I
I am a student programmer using Qt to build a GUI for work. I
I am currently a student programmer using Qt to build a GUI inteface at
I am student programmer and I am using Qt to develop a GUI interface
I am a student programmer using Qt to build a reader Table for my
I'm a student programmer and I am using Qt to build a GUI application.
I am a student programmer using Qt to build a GUI interface fro my
I currently am a student worker at a medium sized university. i work for
I an a graduate student of nuclear physics currently working on a data analysis

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.