I'm having so much trouble with multiple definitions in QT. For ordinary classes, and in my entire library, I just put the implementation and header in the same hpp file. I'm triying to convert an ordinary class in a QObject, so i can use this as a worker to connect with other QThread. After I converted my class in a QObject, I have experienced many multiple definition issues. Suppose that my class now looks like this:
#ifndef MYCLASS_HPP
#define MYCLASS_HPP
#include "common.hpp"
#include <qtGui>
namespace Bial
{
class Image;
class Myclass : QObject{
Image *img;
signal:
void mySignal();
public:
void f();
}
#include "Image.hpp"
namespace Bial{
void Myclass::f(){
}
}
#endif //MYCLASS_HPP
MyClass is a simplification of the Platefinder class. Thai is too big to put here; The issue occurs in the moc_platefinder.o file of this class ans in many functions of my entire library. Totaling 289 multiple definitions issues :
mainwindow.o:/home/lellis/Dropbox/Lellis_Diet/bin/../diet/inc/../bial/File.hpp:1677: first defined here
Sorry for my bad english.
Shouldn't you include 'Q_OBJECT'(http://qt-project.org/doc/qt-4.8/signalsandslots.html) here? :
class Myclass : QObject{
Q_OBJECT // <-- here
signal:
void mySignal();
public:
void f();
Image *img;
}
Edit: Generally 'multiple definitions of ...' can be repared with 'static' (ie 'static void f()')
Edit: Did you look here? Multiple definitions error: one in my file and one in the moc file.