I was trying to connect signal QListWidget->itemChanged
to a custom Slot called checkItemChanged
. I asked for right syntax in this question.
I'm using QT4 so I used old-string syntax as below to connect signal and slot:
connect(listWidget, SIGNAL(itemChanged(QListWidgetItem*)), this , SLOT(checkItemChanged(QListWidgetItem*)));
This connect syntax is declared in a file called mainWindow.cpp
and its header file mainWindow.h
is as below:
class mainWindow : public QWidget
{
Q_OBJECT
public:
mainWindow ( QWidget *parent=0, const char *name=0 );
public slots:
void checkItemChanged(QListWidgetItem*);
I also defined my slot implementation in mainWindow.cpp
as below:
void mainWindow::checkItemChanged(QListWidgetItem* item)
{
if (item->checkState()==true){
qDebug()<<"Item: "<<item->text()<<"Checked";
}else{
qDebug()<<"Item: "<<item->text()<<"UnChecked";
}
}
So it used macro Q_OBJECT as answered here as common reason for no such slot
error.
I run my project in KDevelop IDE, so it will automatically build .moc
file and run qmake
as asked in this answer
However still I face error as below:
Object::connect: No such slot mainWindow::checkItemChanged(QListWidgetItem*) in /home/part/Desktop/project/P/src/gui/mainWindow.cpp:320
I know this is strange but I want to know may be it is related to the fact that QListWidget->itemChanged
is protected? Or there are some other thing that I have missed?