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 7981671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:26:44+00:00 2026-06-04T10:26:44+00:00

If I load a text file into a QTextStream, how would I then populate

  • 0

If I load a text file into a QTextStream, how would I then populate a TableWidget with its data? The text file is tab delimited. Here is what I have so far:

void MainWindow::startParsing()
{
            QStringList stringList;

            int countRows;

             QTextStream in(&textFile);
             QString line;
             if (textFile.open(QIODevice::ReadOnly))
             {
             do
             {
                 line = in.readLine();
                 stringList << line.split("\t", QString::SkipEmptyParts);
             }
             while (!in.atEnd());
             }

             QSet<QString> set = stringList.toSet();
             foreach (const QString &value, set)
                 qDebug() << value;


            countRows = stringList.count();

            //--- define the table's shape ---
            ui->tableWidget_inputPreview->setRowCount(countRows);
            ui->tableWidget_inputPreview->setColumnCount(6);

            //--- create the horizontal (column) headers ---
            QStringList horzHeaders;
            horzHeaders << "HostName" << "Host IP" << "Area" << "Host Interface"
                        << "Router to Ext Network" << "Ext Routes";
            ui->tableWidget_inputPreview->setHorizontalHeaderLabels( horzHeaders );

            //--- create the vertical (row) headers ---
            QStringList vertHeaders;
            ui->tableWidget_inputPreview->setVerticalHeaderLabels( vertHeaders );

            //--- populate the table widget with data from txt file ---

            // TODO: insert data into table
}

Here is a sample of the text file that I’m working with:

#TEST 1                 
#HostName   HostIP  Area    Host Interface  Router to Ext NW    Number of Ext Routes
test1   9.1.1.1 0.0.0.0         
OMG_LOL_101 128.12.101.2    0.0.0.0         
OMG_LOL_102 128.12.102.9    0.0.0.0 128.112.102.9   128.112.102.10  100
WTF_BBQ_149 128.20.180.2    0.0.0.0                 

#HITL 2                 
#HostName   HostIP  Area    Host Interface  Router to Ext NW    Number of Ext Routes
test2   9.1.1.2 0.0.0.0         
WTF_BBQ_111 128.15.110.2    0.0.0.0         
WTF_BBQ_112 128.15.111.2    0.0.0.0         
WTF_BBQ_113 128.15.112.2    0.0.0.0 128.115.112.9   128.115.112.10  100
  • 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-04T10:26:46+00:00Added an answer on June 4, 2026 at 10:26 am
    QTextStream in(&file);
    QList< QStringList > lists;
    QString line;
    do {
        line = in.readLine();
        lists << line.split("\t");
    } while (!line.isNull())
    
    // Set the table size (assuming the rows are all the same length).
    tableWidget.setRowCount( lists.size() );
    tableWidget.setColumnCount( lists[0].size() );
    
    for ( int row = 0; row < lists.size(); ++row ) {
        for ( int column = 0; column < lists[row].size(); ++column ) {
            tableWidget.setItem(row, column, new QTableWidgetItem(lists[row][column]));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to load a text file into a combobox, and then
I am trying to load some data from a text file into a vector
I am trying to load some data from a text file into mysql. I
I would like to load the contents of a text file into a vector<char>
Using COPY statement of PostgreSQL, we can load data from a text file into
I want to do two things in my browser: Load a text file into
I'm trying to load a list of filenames from a text file and then
I'm having a problem reading data from a text file into ms sql. I
I'm trying only to load a part of a text file (*.txt) into the
I have a data set from a text file, 5000 stock's with 751 data

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.