0

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Yasmin Reda
  • 385
  • 1
  • 6
  • 18

2 Answers2

1

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 >).

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
  • even though these problem actually exists i confused the file name with the class name but even after fixing them the errors still exist :/ – Yasmin Reda Mar 15 '13 at 20:50
0

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

HexBlit
  • 1,172
  • 1
  • 13
  • 31
  • but when removing this include it gives this error error: invalid use of incomplete type 'struct QSqlError' – Yasmin Reda Mar 15 '13 at 21:02
  • You may want to start commenting out functions & Includes until you get to a state it compiles and works, then readd and debug as you find those link issues. – HexBlit Mar 15 '13 at 21:09
  • i should've mentioned when removing the DatabaseManager include in main the code compiles with no errors – Yasmin Reda Mar 15 '13 at 21:16