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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:31:03+00:00 2026-05-27T06:31:03+00:00

I create a QTableview with a QStandardItemModel, after editing the QStandardItem the type changed

  • 0

I create a QTableview with a QStandardItemModel, after editing the QStandardItem
the type changed from unsigned int to int.
This behavior just happen to unsigned int and just while the user is editing it, other datatypes stay.

window.cpp

#include "window.h"
#include "ui_window.h"
#include <QTableView>
#include <QStandardItem>
#include <QDebug>

Window::Window(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Window)
{
    ui->setupUi(this);

    QTableView *tblview = new QTableView(this);
    model = new QStandardItemModel(0,0);

    tblview->setModel(model);

    QStandardItem *data=new QStandardItem;
    data->setEditable(true);
    data->setData(QVariant((uint)1), Qt::DisplayRole);
    model->setItem(0, 0, data);
    tblview->show();

    QModelIndex index = model->index( 0, 0, QModelIndex() );

    tblview->setGeometry(0,0,200,200);

    //result QVariant(uint, 1)
    qDebug() << model->data(index);



    connect(model, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(dataChanged(QStandardItem*)));
}

Window::~Window()
{
    delete ui;
}

void Window::dataChanged(QStandardItem* stditem)
{
    //result
    //QVariant(int, 3)
    //expected result 
    //QVariant(uint, 3)
    qDebug() << model->data(stditem->index());

}

window.h

#ifndef WINDOW_H
#define WINDOW_H

#include <QMainWindow>
#include <QStandardItem>

namespace Ui {
    class Window;
}

class Window : public QMainWindow
{
    Q_OBJECT

public:
    explicit Window(QWidget *parent = 0);
    ~Window();

private:
    Ui::Window *ui;
    QStandardItemModel* model;

private slots:
    void dataChanged(QStandardItem*);
};

#endif // WINDOW_H
  • 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-27T06:31:04+00:00Added an answer on May 27, 2026 at 6:31 am

    The second qDebug() does not print nothing because you do not define the role. This will work:

    qDebug() << stditem->data(Qt::DisplayRole);
    

    Now concerning the conversion from an uint QVariant to an int after the edit. This is natural and can be explained as follows:

    First you have a QVariant that is uint

    QVariant v = QVariant((uint) 5)); // It is uint now... 
    

    After the edit, the model changes its value with the int value that is entered

    v = QVariant(10); // Now v is not uint anymore but int
    

    In order to avoid it you should subclass the QStandardItemModel, and reimplement the setData function. There you should explicitly cast the new value to uint.

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

Sidebar

Related Questions

create table ImagenesUsuario { idImagen int primary key not null IDENTITY } This doesn't
I'm using PyQt to create a GUI application. In a view inherited from QTableView,
create table person ( name varchar(15), attr1 varchar(15), attr2 varchar(1), attr3 char(1), attr4 int
Create Proc CrearNuevoAnuncio @Titulo varchar(250), @Precio int, @Descripcion varchar(250), @IDCategoria int, @IDImagen int, @Login
CREATE TABLE #Report( Cell int, CellValue double) Error here DECLARE @Report TABLE ( Cell
The tableview is populated from a .plist. I want to be create an ADD
How do I create a NavigationController with a TableView inside of it from scratch
I am developing an application that updates the data in QTableView from apache server
I want to create a tableview like this. All sections have custom section header
I have created my own class that derives from QTableView, the associated model is

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.