the problem is keyword static and way you organized your code.
In this context keyword static mean: this symbol should be visible only in current unit (usually cpp file) and not shared between units.
Result is that you are defining this symbol again every time you are including this header file. In some source files you are including this header file but you are not using this symbol in this source file (this is why you have a warning).
You should do it like that:
In header file:
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QtSql/QSqlDatabase>
bool createConnection(); // declaration of method
#endif // CONNECTION_H
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QtSql/QSqlDatabase>
bool createConnection(); // declaration of method
#endif // CONNECTION_H
To copy to clipboard, switch view to plain text mode
and in respective cpp file:
#include <yourHeaderFile.h>
// definition of symbol
bool createConnection()
{
db.setHostName("myhostname");
db.setPort(5432);
db.setDatabaseName("mydbname");
db.setUserName("myusn");
db.setPassword("mypwd");
if (!db.open()) return false;
else return true;
}
#include <yourHeaderFile.h>
// definition of symbol
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("myhostname");
db.setPort(5432);
db.setDatabaseName("mydbname");
db.setUserName("myusn");
db.setPassword("mypwd");
if (!db.open()) return false;
else return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks