سؤال

I have a QStandardModel. I connect its itemChanged signal to my own slot.

m_model = new QStandardItemModel(this);  
connect(m_model, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(changed(QStandardItem*)));

The slot looks like this:

void Class::changed(QStandardItem * item) {
    //    ui->pushButton->setText("change");
    QString name = item->parent()->data().toString();
    ui->pushButton->setText(item->data().toString());
}  

The pushButton text will change to "change", so my slot seems to work. However, item->data().toString() is always empty.

How do I do this right?

هل كانت مفيدة؟

المحلول

I think you should use QStandardItem::text() method. Like this: QString name = item->parent()->text();

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top