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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:24:52+00:00 2026-05-15T13:24:52+00:00

So I have a question very closely related to another question I’ve seen on

  • 0

So I have a question very closely related to another question I’ve seen on here but when I tried posing my question there I got no responses, I’m hoping by asking this as a fresh question someone can help me out. Basically I want simply copy a portion of my table that I’ve created so that I can paste it to an excel file. Here’s what I have:

    QAbstractItemModel *abmodel = ui.tableview->model();
    QItemSelectionModel *model = ui.tableview->selectionModel();
    QModelIndexList list = model->selectionIndexes();
    qSort(list);
    QModelIndex index = list.first();
    for(int i = 0; i < list.size(); i++)
{
    QModelIndex index = list.at(i);
    QString text = abmodel->data(index).toString();
    copy_table.append(text);

    if(index.row() != previous.row())
    {
        copy_table.append('\n');
    }
    else
    {
        copy_table.append('\t');
    }
    previous = index;
}

QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(copy_table);

This will copy a column fine, but when I attempt to copy a row or say a 2×2 subtable the row index gets messed up, incorrectly assigning the row index for the values. Any thoughts?

  • 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-05-15T13:24:54+00:00Added an answer on May 15, 2026 at 1:24 pm

    Well, already figured it out, sorry anyone that wasted their time and looked.

    void TestCopyTable::on_pushButton_copy_clicked()
    {
    QAbstractItemModel *abmodel = ui.tableView->model();
    QItemSelectionModel * model = ui.tableView->selectionModel();
    QModelIndexList list = model->selectedIndexes();
    
    qSort(list);
    
    if(list.size() < 1)
        return;
    
    QString copy_table;
    QModelIndex last = list.last();
    QModelIndex previous = list.first();
    
    list.removeFirst();
    
    for(int i = 0; i < list.size(); i++)
    {
        QVariant data = abmodel->data(previous);
        QString text = data.toString();
    
        QModelIndex index = list.at(i);
        copy_table.append(text);
    
        if(index.row() != previous.row())
    
        {
            copy_table.append('\n');
        }
        else
        {
            copy_table.append('\t');
        }
        previous = index;
    }
    
    copy_table.append(abmodel->data(list.last()).toString());
    copy_table.append('\n');
    
    QClipboard *clipboard = QApplication::clipboard();
    clipboard->setText(copy_table);
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is closely related to anothewr question I have asked but since this is
Great site! I have a question I haven't seen answered. I am very new
I have a very theoretical question: Is there a way to ban the use
I have a question very similiar to another question: Get name of property as
I have question that seems very simple, but I just can't get it right.
I have very simple question but the answer is still not clear. If i
I have a question related to jquery. Basically I want to do a very
I have a question very similar to this one but the answer does not
I have question, maybe it's not critical in programming, but to me it's very
I have a question that must surely seem very trivial, but the answer has

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.