2
votes

I used below syntax in Qt5 according to new connect syntax to avoid type mismatches of slot and signals for a a QListWidget with checkable items.

connect(item, &QListWidget::itemChanged,this , &mainWindow::checkItemChanged);

I want to run my slot in case any of list item changed its state. In order to this this I used itemChanged signal due to this answer, but it is protected and compile time error raise as below:

error: ‘void QListWidget::itemChanged(QListWidgetItem*)’ is protected

How can I handles this? Should I subclass my own QListWidget or there are some other solutions to this?

1
What you propose is the only option I can think of.apalomer
Are you sure you're using Qt5? QListWidget::itemChanged should be public in Qt5 but may have been protected in Qt4.G.M.
In both Qt4 and Qt5 this signal declared under Q_SIGNALS macro which resolves to be public in Qt5 and protected for Qt4. You might use Qt4 connection style instead.vahancho

1 Answers

2
votes

You can use the more appropriate syntax according to Qt version:

#if QT_VERSION >= 0x050000
    connect(item, &QListWidget::itemChanged, this , &MainWindow::checkItemChanged);
#else
    connect(item, SIGNAL(checkItemChanged), this , SLOT(checkItemChanged));
#endif

(or the 'old string-based' for all versions).