Unsolved One more basic C++ question
-
I am still unsure about C++ syntax . The attached "connect": code gives me errors. I need help with C++ syntax.
/media/f/QT/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT_18112020/device.cpp:125: error: **cannot call member function** 'void QListWidget::itemClicked(QListWidgetItem*)' **without object** &QListWidget::itemClicked(&item), // &item), ^
/media/f/QT/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT_18112020/device.cpp:127: error: cannot call member function 'void QListWidget::addItem(QListWidgetItem*)' without object &QListWidget::addItem(&item)); ^
Please help me with understanding what I am doing wrong.
C++ code correction would be also welcome, hopefully with explanation of my error.connect(ui->list, &QListWidget::itemClicked(&item), , ui->list_2, &QListWidget::addItem(&item));
-
Using the new signal&slot syntax, you don't need to worry about any parameters. This is done automatically.
Remove the
(&item)
part on both sides (signal and slot) and it should be fine -
connect(ui->list, &QListWidget::itemClicked , ui->list_2, &QListWidget::addItem);
https://doc.qt.io/qt-5/signalsandslots.html
If using overloaded signals see https://stackoverflow.com/questions/16794695/connecting-overloaded-signals-and-slots-in-qt-5