I'm trying to write a wrapper so threaded classes have a common interface--so I can write threaded classes expecting certain available functionality, and I and others can write clients, expecting some common functionality.
So, I wrote an abstract class to act as my "middle man."
#ifndef THREADBASE_H
#define THREADBASE_H
#include <QThread>
{
public:
ThreadBase();
signals:
void progressChanged(int);
void exceptionOccurred(int);
protected:
void run();
virtual void runThread() = 0;
};
ThreadBase
::ThreadBase() : QThread(0){
}
void ThreadBase::run()
{
runThread();
}
#endif // THREADBASE_H
#ifndef THREADBASE_H
#define THREADBASE_H
#include <QThread>
class ThreadBase : public QThread
{
public:
ThreadBase();
signals:
void progressChanged(int);
void exceptionOccurred(int);
protected:
void run();
virtual void runThread() = 0;
};
ThreadBase::ThreadBase() : QThread(0)
{
}
void ThreadBase::run()
{
runThread();
}
#endif // THREADBASE_H
To copy to clipboard, switch view to plain text mode
This compiled fine. I then tried writing a derived class.
// testsubclass.h
#ifndef TESTSUBCLASS_H
#define TESTSUBCLASS_H
#include "threadbase.h"
class TestSubClass : public ThreadBase
{
public:
TestSubClass();
protected:
void runThread();
};
#endif // TESTSUBCLASS_H
// testsubclass.h
#ifndef TESTSUBCLASS_H
#define TESTSUBCLASS_H
#include "threadbase.h"
class TestSubClass : public ThreadBase
{
public:
TestSubClass();
protected:
void runThread();
};
#endif // TESTSUBCLASS_H
To copy to clipboard, switch view to plain text mode
// testsubclass.cpp
#include "testsubclass.h"
TestSubClass::TestSubClass() : ThreadBase()
{
}
void TestSubClass::runThread()
{
for(int i = 0; i < 100; i++)
{
emit progressChanged(i);
wait(100);
}
emit progressChanged(100);
}
// testsubclass.cpp
#include "testsubclass.h"
TestSubClass::TestSubClass() : ThreadBase()
{
}
void TestSubClass::runThread()
{
for(int i = 0; i < 100; i++)
{
emit progressChanged(i);
wait(100);
}
emit progressChanged(100);
}
To copy to clipboard, switch view to plain text mode
I'm receiving a compiler error on lines 12 and 15 in testsubclass.cpp:
undefined reference to `ThreadBase::progressChanged(int)'
undefined reference to `ThreadBase::progressChanged(int)'
To copy to clipboard, switch view to plain text mode
I think I'm having a mind-block, because I have done this before in other classes, and it works. As a derived class, shouldn't TestSubClass have access to the public members of ThreadBase? This might be a C++ question, but I didn't know if there were special rules for using signals in abstract classes that I missed.
P.S. I'm in Windows, using MinGW, with gcc version 3.4.5.
Bookmarks