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

  • Home
  • SEARCH
  • 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 6135043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:25:53+00:00 2026-05-23T17:25:53+00:00

I have an issue with a table->setItem(index, 0, widg); statement having unwanted side-effects. I

  • 0

I have an issue with a “table->setItem(index, 0, widg);” statement having unwanted side-effects.

I have a map of QStrings to QStrings:

QMap<QString, QString> levelPlist;

Later on, I have a function to fill a QTableWidget with the keys and values contained in this map. So, I have the following function:

void MainWindow::updateLevelPlistTable()
{
    QTableWidget *table = ui->levelPlistTableWidget;

    int count = levelPlist.count();
    table->setRowCount(count);
    table->setColumnCount(2);


    QMap<QString, QString>::const_iterator i;
    int index = 0;

    for (i = levelPlist.constBegin(); i != levelPlist.constEnd(); ++i)
    {
        qDebug(QString("BG TEX pre  - " + levelPlist.value("background_texture")).toAscii());
        QTableWidgetItem *widg = new QTableWidgetItem(i.key());
        qDebug(QString("BG TEX pre mid  - " + levelPlist.value("background_texture")).toAscii());
        table->setItem(index, 0, widg);
        qDebug(QString("BG TEX mid  - " + levelPlist.value("background_texture")).toAscii());
        table->setItem(index, 1, new QTableWidgetItem(i.value()));

        qDebug(QString("BG TEX post - " + levelPlist.value("background_texture")).toAscii());
        if(index == 0)
        {
            qDebug(QString("Key - " + i.key() + ", Value - " + i.value()).toAscii());
        }
        index++;
    }
}

Pardon all of the debugging text, but that’s how I was able to narrow down exactly where the problem is. Here’s some of the output from when the function runs (“background_texture” initially maps to “nope”):

BG TEX pre  - nope
BG TEX pre mid  - nope
BG TEX mid  - background_texture
BG TEX post - background_texture
Key - background_texture, Value - background_texture
BG TEX pre  - background_texture
BG TEX pre mid  - background_texture
BG TEX mid  - level_height
BG TEX post - 600
BG TEX pre  - 600
BG TEX pre mid  - 600
BG TEX mid  - level_width
BG TEX post - 400

As you can see, the value changes between the “pre mid” and “mid” debug statements, which means that executing the statement of “table->setItem(index, 0, widg);” changes the value of the “background_texture” key to whatever the latest i.value() is.

Why?

Edit: Full debug information:

void MainWindow::updateLevelPlistTable()
{
    QTableWidget *table = ui->levelPlistTableWidget;

    int count = levelPlist.count();
    table->setRowCount(count);
    table->setColumnCount(2);


    QMap<QString, QString>::const_iterator i;
    int index = 0;

    for (i = levelPlist.constBegin(); i != levelPlist.constEnd(); ++i)
    {
        QTableWidgetItem *widg = new QTableWidgetItem(i.key());
        table->setItem(index, 0, widg);
        qDebug() << "before - " << levelPlist;
        table->setItem(index, 1, new QTableWidgetItem(i.value()));
        qDebug() << "after - " << levelPlist << "\n";
        index++;
    }
}

produces

before -  QMap(("background_texture", "background_texture")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 
after -  QMap(("background_texture", "background_texture")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 

before -  QMap(("background_texture", "level_height")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 
after -  QMap(("background_texture", "600")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 

before -  QMap(("background_texture", "level_width")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 
after -  QMap(("background_texture", "400")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 

before -  QMap(("background_texture", "start_x")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 
after -  QMap(("background_texture", "250")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 

before -  QMap(("background_texture", "start_y")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 
after -  QMap(("background_texture", "50")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 

before -  QMap(("background_texture", "world")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 
after -  QMap(("background_texture", "null")("level_height", "600")("level_width", "400")("start_x", "250")("start_y", "50")("world", "null")) 
  • 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-23T17:25:54+00:00Added an answer on May 23, 2026 at 5:25 pm

    Can you show the debug output of the whole map every time instead of the value stored under the key?
    One reason for such a behaviour could be that some slot listens to a signal emitted by the table model and modifies the map.

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

Sidebar

Related Questions

I'm having an issue bending my head around this one. I have a table
I have a pretty common layout issue that I have traditionally used a table
I have an application that reads a table from a database. I issue an
I'm seeing basically the same issue described here I have a table that starts
I have a MySQL database of newspaper articles. There's a volume table, an issue
i have a table and i have little issue with groupby month CREATE TABLE
I have an issue with the border color in the table in this page:
I have an issue with a table containing three cells in one row. Two
I have an issue with single table inheritance and I'm not sure if I'm
I have a table in mysql having two fileds title_en,title_es If language is ENGLISH

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.