我有一个而QListView从中我得到化QAbstractItemModel与列表 - >模型();

在此之后,我想将dataChanged信号连接到我的一个自定义的QObject:

 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; 

这是我的自定义对象:

 class CustomObject : public QObject
{
    Q_OBJECT

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

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

private:

}; 

我是不是做错了什么? QObject的调用返回真,我在onText功能的清点,但当而QListView改变没有什么是永远印。

有帮助吗?

解决方案

这可能意味着该信号是从未发射。尝试调用

模型 - >使用setData(模型 - >指数(0,0),Qt的:: EditRole,3.14);

如果一个人没有援引你的插槽中,然后setData()的实施可能是车和不排放dataChanged(QModelIndex,QModelIndex),否则customObject_已被删除。

如果没有的话,你需要给我们更多的信息。

其他提示

也许有和你的功能..

但如果是这个问题,就应该由你的功能显示的错误...


可能这个信号不emmited。尝试与另一个信号连接..可以测试这样说,这..

你有没有试着用

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

?又名确保参数是按引用传递。 检查本教程

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top