-2

While I've been programing a connection between 2 QThread in QT. First is QMainWindow and second is my own class DB, which base on QThread, becouse I'd like don't to stop GUI thread during downloading data from data base server. But when I've add signals to my new class, everything goes wrong. I've recieved errors:

ERRORS

Error   LNK2005 "public: void __cdecl DB::statusChanged(void)" (?statusChanged@DB@@QEAAXXZ) already defined in mocs_compilation.cpp.obj 
Error   LNK2005 "public: void __cdecl DB::dataDownloaded(void)" (?dataDownloaded@DB@@QEAAXXZ) already defined in mocs_compilation.cpp.obj     
Error   LNK1169 one or more multiply defined symbols found

A minute ago every thing is ok with the code, but when I add signals to the files, program stop working.

CODE

DB.h

#ifndef DB_H
#define DB_H

#include <qthread.h>
class patient;

class DB: public QThread
{
    Q_OBJECT
//--------------------
//CONSTRUCTORS AND DESTRUCTORS
//--------------------
public:
    DB();
    DB(std::vector<patient> *list);
    ~DB();
//--------------------
//SLOTS AND SIGNALS
//--------------------
signals:
    void statusChanged();
    void dataDownloaded();
private:
    std::vector<patient> *listOfPatients;
//--------------------
//METHODS
//--------------------
public:
    void run();
    DB& operator=(const DB& source);
};
#endif  //DB_H

DB.cpp

#include "DB.h"
#include "patient.h"

//--------------------
//CONSTRUCTORS AND DESTRUCTORS
//--------------------
DB::DB()
{
    listOfPatients = nullptr;
}
DB::DB(std::vector<patient> *list)
{
    listOfPatients = list;
}
DB::~DB()
{
}
//--------------------
//SIGNAL AND SLOTS
//--------------------
void statusChanged()
{
}
void dataDownloaded()
{
}
//--------------------
//METHODS
//--------------------
void DB::run()
{
    //import data from DB - to be implement
    emit dataDownloaded();
}

DB& DB::operator=(const DB &source)
{
    this->listOfPatients = source.listOfPatients;
    return *this;
}

Have you got any ideas what was wrong?

Miziol
  • 42
  • 8

1 Answers1

-2

The problem was that I've tried to define the signals, which was define in QT automaticly. I don't know that but one comment motivate me to check what happand when I delete definition of my signals in DB.cpp and this was the clue of the problem.

So the correct DB.cpp file was:

#include "DB.h"
#include "patient.h"

//--------------------
//CONSTRUCTORS AND DESTRUCTORS
//--------------------
DB::DB()
{
    listOfPatients = nullptr;
}
DB::DB(std::vector<patient> *list)
{
    listOfPatients = list;
}
DB::~DB()
{
}
//--------------------
//SIGNAL AND SLOTS
//--------------------

//NO SIGNAL DEFINITION THERE

//--------------------
//METHODS
//--------------------
void DB::run()
{
    //import data from DB - to be implement
    emit dataDownloaded();
}

DB& DB::operator=(const DB &source)
{
    this->listOfPatients = source.listOfPatients;
    return *this;
}
Miziol
  • 42
  • 8