Search code examples
c++qtsignals-slotsqlistwidget

How to issue signal each time a row is edited in QListWidget?


class genericTaskList : public QListWidget
{
    Q_OBJECT  
    public:
        QListWidgetItem *defaultText;

        genericTaskList (QWidget *parentWidget)
        {
            setParent      (parentWidget);
            setFixedSize (445, 445);

            defaultText = new QListWidgetItem ("Double click here to compose the task");
            defaultText->setFlags (defaultText->flags () | Qt :: ItemIsEditable);

            insertItem     (0, defaultText);

            QObject :: connect (this, SIGNAL (currentRowChanged (int)), this, SLOT (addDefaultText (int)));
        }

    public slots:
        void addDefaultText (int rr)
        {
            std::cout << "\ndsklfjsdklfhsdklhfkjsdf\n";

            insertItem (++rr, defaultText);
        }
};

This code is supposed to issue a signal each time the row gets edited.

After I call "insertItem" in the constructor, the signal is issued.
But, that's it. It never gets issued after that - no matter how many times I edit the row.

What am I missing?


Solution

  • currentRowChanged indicates the row selection has changed, not the content of the row. Perhaps you want to use currentTextChanged or itemChanged instead.

    The reuse of the word current and changed in the QT docs is quite confusing.