2

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?

Louis Langholtz
  • 2,913
  • 3
  • 17
  • 40
VSB
  • 9,825
  • 16
  • 72
  • 145
  • What you propose is the only option I can think of. – apalomer Jan 02 '18 at 11:05
  • 1
    Are you *sure* you're using `Qt5`? [`QListWidget::itemChanged`](http://doc.qt.io/qt-5/qlistwidget.html#itemChanged) should be `public` in `Qt5` but may have been `protected` in `Qt4`. – G.M. Jan 02 '18 at 11:10
  • 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 Jan 02 '18 at 11:28

1 Answers1

2

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).

p-a-o-l-o
  • 9,807
  • 2
  • 22
  • 35