1

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?

VSB
  • 9,825
  • 16
  • 72
  • 145
  • did you tried to rebuild whole project after runing qmake? – Amir Rasulov Jan 09 '18 at 08:17
  • I did clean project and then rebuild it. The strange thing is that other connect methods in my project in the same file are working flawlessly but I have no idea why this one is not working. – VSB Jan 09 '18 at 13:01
  • 1
    Try to manually delete all files in build directory and then run qmake and rebuild. Sometimes it helps – Amir Rasulov Jan 09 '18 at 14:39
  • I see no reason why this shouldn't work. As @AmirRasulov points out sometimes there are remains from previous builds (esp. moc files) that have to be cleaned up manually. If the problem persists then provide a [mcve] instead of snippets. – Murphy Jan 10 '18 at 10:14

0 Answers0