views:

429

answers:

3

Hey,

I have a QListView from which I obtain a QAbstractItemModel with list->model();

After this, I want to connect the dataChanged signal to a custom QObject of mine:

 if( QObject::connect(model, SIGNAL(dataChanged (const QModelIndex , const QModelIndex ) ),
                        customObject_,SLOT(onText(const QModelIndex , const QModelIndex )) ) )
     cout << "SIGNAL SLOT connection successful" << endl;
 else
     cout << "SIGNAL SLOT connection ERROR" << endl;

here is my custom object:

 class CustomObject : public QObject
{
    Q_OBJECT

public:
    CustomObject (QObject *parent);
    ~CustomObject ();

public slots:
    void onText(const QModelIndex & topLeft, const QModelIndex & bottomRight );

private:

};

Am I doing anything wrong? The QObject call returns true, I have a cout in the onText function, but nothing is ever printed when the QListView is Changed.

A: 

Did you try with

QObject::connect(model, SIGNAL(dataChanged (const QModelIndex &, const QModelIndex &) ),
                    customObject_,SLOT(onText(const QModelIndex &, const QModelIndex &)) );

? aka make sure the parameters are passed by reference. Check this tutorial.

OneOfOne
OP mentioned `QObject::connect()` returns `true`.
A: 

maybe there is & in your function..

but if it was the problem, it should display an error by your function...


probably this signal is not emmited. Try to connect with another signal.. you can test it like that..

ufukgun
+1  A: 

That probably means that the signal is never emitted. Try calling

model->setData( model->index( 0, 0 ), Qt::EditRole, 3.14 );

If that one doesn't invoke your slot, then the implementation of setData() is probably buggy and doesn't emit dataChanged(QModelIndex,QModelIndex), or else customObject_ has since been deleted.

If neither is the case, you need to give us more information.

setData did not invoke my slot, and customObject is not deleted, I will try a different slot. Thanks.
David Menard
Any suggestions on wich on to use?
David Menard
connected to rowsInserted and works fine, thanks
David Menard