I am having trouble calling a slot directly from subclass of QListWidget. It fails to link claiming an undefined reference to MyClass::MySlot. If instead of calling it, I just connect to slot and emit the appropriate signal everything works fine. It seems to me that it's probably a compiler/qmake/makefile issue but I'm not sure. Below is a rough approximation of the issue I'm having. I have omitted all the #include for the sake of brevity.
I have a subclass of QObject that looks roughly like
Q_OBJECT
public:
void MyFunc() {
// do some work
}
public slots:
void MySlot() {
// do some work
}
}
class MyClass : public QObject {
Q_OBJECT
public:
MyClass(QObject* parent = NULL) : QObject(parent) { }
void MyFunc() {
// do some work
}
public slots:
void MySlot() {
// do some work
}
}
To copy to clipboard, switch view to plain text mode
And...
Q_OBJECT
private:
MyClass* foo;
public:
public slots:
void bar() {
// won't compile, linker fails - undefined reference to 'MyClass::MySlot'
foo->MySlot();
}
void baz() {
// this compiles and works fine
QObject::connect(this,
SIGNAL(callSlot
), foo,
SLOT(MySlot
()));
emit callSlot();
QObject::disconnect(this,
SIGNAL(callSlot
), foo,
SLOT(MySlot
()));
// also works
foo->MyFunc();
}
signals:
void callSlot();
}
class MyListWidget : public QListWidget {
Q_OBJECT
private:
MyClass* foo;
public:
MyListWidget(QWidget* parent = NULL) : QListWidget(parent) { }
public slots:
void bar() {
// won't compile, linker fails - undefined reference to 'MyClass::MySlot'
foo->MySlot();
}
void baz() {
// this compiles and works fine
QObject::connect(this, SIGNAL(callSlot), foo, SLOT(MySlot()));
emit callSlot();
QObject::disconnect(this, SIGNAL(callSlot), foo, SLOT(MySlot()));
// also works
foo->MyFunc();
}
signals:
void callSlot();
}
To copy to clipboard, switch view to plain text mode
Bookmarks