Undefined reference to function if in .cpp file
Hi All,
I feel like this should be simple I am just not sure what is going on.
I've got a ProgressUpdator function used to handle the signal updates of a progress bar:
Code:
#ifndef PROGRESSUPDATOR_H
#define PROGRESSUPDATOR_H
#include <QObject>
class ProgressUpdator
: public QObject{
Q_OBJECT
public:
explicit ProgressUpdator
(QObject *parent
= nullptr
);
signals:
void updateProgress(int progress);
public:
void setProgress(int progress);
};
#endif // PROGRESSUPDATOR_H
with my .cpp file being:
Code:
#include "progressupdator.h"
{}
void ProgressUpdator::setProgress(int progress)
{
emit updateProgress(progress);
}
This is called from a class performing the algorithm
Code:
for (int i=0; i<100; ++i)
{
// Do work
progressUpdator->setProgress(i);
}
Any my .pro file has all files added to HEADERS and SOURCES as needed.
But this comes up with a undefined reference to setProgress().
If I try and get around this and put the contents of setProgress in the header file as an inline function the linker then complains that it cannot find the reference to updateProgress instead.
I've also tried running qmake and rebuilding but this doesn't make a difference.
Thanks in advance.
Re: Undefined reference to function if in .cpp file
You're including "progressupdator.h" in the place where you are using the ProgressUpdator class, right? Try manually deleting all of the output and generated files and doing a clean qmake / rebuild.
I don't use Qt Creator much, but if there is a verbose mode you can turn on for the build, that might tell you if the compiled object files for ProgressUpdator are actually being linked in.
Re: Undefined reference to function if in .cpp file
Quote:
Originally Posted by
Cheesy135
But this comes up with a undefined reference to setProgress().
OK, if the linker is complaining then the object file containing the function is either not being included in the link, or is included but does not export the function (could be an old version for example). Hard to tell without the actual compile/link output.