Yasmin Reda
Yasmin Reda

Reputation: 385

"First defined here" error

I have an error that i can't include my header file in more than one cpp even though i have guard headers. when removing the include of DatabaseManager from main the ccode builds just fine

here is the header file :

#ifndef DATABASEMANAGER_H
#define DATABASEMANAGER_H
#include <QSqlDatabase>
#include <QSqlQuery>
class DatabaseManager
{
 private:
    QSqlDatabase PatternLibrary;
    QSqlQuery query;
 public:
  DatabaseManager();
};
#endif

here is the .cpp:

#include "DatabaseManager.h"
#include <QSqlError>
#include <QDebug>

DatabaseManager::DatabaseManager()
{
}

and here is the main :

#include "DatabaseManager.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    DatabaseManager x;
    MainWindow w;
    w.show();

    return a.exec();
}

giving these errors :

/Code/DB_RangePattern-build-desktop-Qt_4_8_1_in_PATH_System_Debug/../DB_RangePattern/main.cpp:6: error: first defined here

collect2: ld returned 1 exit status

Upvotes: 0

Views: 9953

Answers (2)

HexBlit
HexBlit

Reputation: 1162

I am pretty sure QSqlDatabase uses/include QSqlError because it has a defined public function

QSqlError   lastError () const

and redefinition will come from your including QSqlError

Upvotes: 0

Joseph Mansfield
Joseph Mansfield

Reputation: 110658

You've only posted one line of a larger error, but I can hazard a guess at what the problem is. You seem to be unsure of whether your class is DataBaseManager or DatabaseManager (note the change in capital B).

Also, if your header file is with the rest of your source files, make sure you're doing #include "DatabaseManager.h" (not using < and >).

Upvotes: 1

Related Questions