Linking error: LNK2019 & LNK1120 - when creating/connecting a SIGNAL
My goal here is to create a signal "expandParentItem" in my QFileSystemModel subclass so that when a parent item is checked in the associated QtreeView, the QtreeView can automatically expand it to show its children.
I define and I emit the signal like this:
FileSysSelectModel.h
Code:
#ifndef FILESYSSELECTMODEL_H
#define FILESYSSELECTMODEL_H
#include<QFileSystemModel>
#include <QSet>
#include <QPersistentModelIndex>
#include <QVariant>
class FileSysSelectModel: public QFileSystemModel
{
private:
QSet<QPersistentModelIndex> m_checkTable;
public:
int FileSysSelectModel
::columnCount(const QModelIndex &parent
) const;
virtual Qt
::ItemFlags FileSysSelectModel
::flags(const QModelIndex &index
) const;
virtual bool FileSysSelectModel
::setData(const QModelIndex &index,
const QVariant &value,
int role
);
signals:
};
#endif // FILESYSSELECTMODEL_H
Function managing the signal in FileSysSelectModel.cpp
Code:
//if the current item has children:
// check all the child items if the parent item is checked.
// uncheck all the child items if the parent item is unchecked.
{
if (firstChild.isValid())
{
if(value == Qt::Checked) emit expandParentItem(index);
int i = 0;
while(1)
{
currentChild = index.child(i,0);
//Recursive call
FileSysSelectModel::updateSubMembers(currentChild, value);
if (!currentChild.isValid()) break;
if(value == Qt::Checked) m_checkTable.insert(currentChild); else m_checkTable.remove(currentChild);
i = i+1;
}
emit dataChanged(firstChild, currentChild);
}
}
I connect the signal to the QtreeView in my main window like this:
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_fileSystemModel = new FileSysSelectModel;
m_fileSystemModel
->setRootPath
(QDir::currentPath());
ui->scriptFileView->setModel(m_fileSystemModel);
}
MainWindow::~MainWindow()
{
delete ui;
}
When I try to compile, I get the following error message:
FileSysSelectModel.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall FileSysSelectModel::expandParentItem(class QModelIndex const &)" (?expandParentItem@FileSysSelectModel@@QAEXABVQMod elIndex@@@Z) referenced in function "private: void __thiscall FileSysSelectModel::updateSubMembers(class QModelIndex const &,class QVariant const &)" (?updateSubMembers@FileSysSelectModel@@AAEXABVQMod elIndex@@ABVQVariant@@@Z)
debug\Designer_test.exe:-1: error: LNK1120: 1 unresolved externals
I'm new to Qt and I'm having a hard time understanding this error message.
Could someone help me with this issue?
Re: Linking error: LNK2019 & LNK1120 - when creating/connecting a SIGNAL
You need the Q_OBJECT macro in the class declaration. You must rerun qmake after adding this macro.
The code for signals (the bit your linker cannot find) is generated by moc, built and linked into your program courtesy of the Makefile qmake generates. These rules are triggered by the presence of the Q_OBJECT macro, which expands to include some support infrastructure for the Qt metaobject system and generated code.