[Qt-interest] using QStandardItemModel

sarvesh saran aquarian.thunder at gmail.com
Fri Mar 4 14:18:57 CET 2011


Hi,

You may want to look at this:
http://doc.qt.nokia.com/latest/qabstractitemmodel.html#setData

<http://doc.qt.nokia.com/latest/qabstractitemmodel.html#setData>thanks,
Sarvesh

On Thu, Mar 3, 2011 at 3:32 PM, Graham Labdon <
Graham.Labdon at avalonsciences.com> wrote:

> Hi
> I have just started to experiment with QStandardItemModel.
> So I set up my model and view and now cant see how the data in the model
> gets updated.
> My application displays the tree as expected and allows the user to edit
> the contents
> But how do I get the data back into the model
>
> .h file
> #ifndef MVC_H
> #define MVC_H
>
> #include <QtGui/QWidget>
> #include "ui_mvc.h"
>
> class QStandardItemModel;
> class QStandardItem;
>
> class MVC : public QWidget
> {
>    Q_OBJECT
>
> public:
>    MVC(QWidget *parent = 0);
>    ~MVC();
>
> private:
>    Ui::MVCClass ui;
>    QStandardItemModel *model;
>    QStringList data;
>
>   private slots:
>   void onButtonPressed();
>   void itemChanged(QStandardItem* item);
> };
>
> #endif // MVC_H
>
> .cpp
> #include "mvc.h"
> #include <QtGui>
> #include <QStandardItem>
>
> MVC::MVC(QWidget *parent)
>    : QWidget(parent)
> {
>        ui.setupUi(this);
>
>        connect(ui.pushButton,
>                        SIGNAL(pressed()),
>                        SLOT(onButtonPressed()));
>
>        QStringList header;
>        header << "Property" << "Value";
>
>         model = new QStandardItemModel();
>         model->setHorizontalHeaderLabels(header);
>         QStandardItem *parentItem = model->invisibleRootItem();
>         for (int i = 0; i < 4; ++i)
>         {
>                 data.append(QString("item %0").arg(i));
>             QStandardItem *item = new QStandardItem(data[i]);
>             item->setEditable(true);
>             parentItem->appendRow(item);
>             parentItem = item;
>         }
>         connect(model,
>                    SIGNAL(itemChanged(QStandardItem*)),
>                    SLOT(itemChanged(QStandardItem*)));
>        ui.treeView->setModel(model);
> }
>
> MVC::~MVC()
> {
>
> }
>
> void MVC::onButtonPressed()
> {
>        for (int i = 0; i < 4; ++i)
>        {
>                QString s = data[i];
>                qDebug() << "s : " << s << "\\n";
>        }
> }
>
> void MVC::itemChanged(QStandardItem* item)
> {
>
> }
>
>
> Graham
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110304/eadbc4a5/attachment.html 


More information about the Qt-interest-old mailing list