I’m having a static linking problem in my C++ app. I’m hoping you can help. Code for header and source below.
#ifndef PRACTICARDSDB_H
#define PRACTICARDSDB_H
#include "cardset.h"
#include "card.h"
#include "filter.h"
class PractiCardsDB
{
public:
PractiCardsDB();
static void resetAll();
static void resetDates();
static CardSet getCardSet();
static CardSet getCardSet(Filter filter);
static void addCard(Card card);
static void editCard(Card card);
static void deleteCard(Card card);
static bool createConnection();
};
#endif // PRACTICARDSDB_H
Above is the header file and below is the source file.
#include "practicardsdb.h"
#include <QtSql/QSqlDatabase>
#include <QMessageBox>
PractiCardsDB::PractiCardsDB() {}
static bool PractiCardsDB::createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("EnglishSpanish");
if (!db.open())
{
return false;
}
return true;
}
The error I receive is: cannot declare member function ‘static bool PractiCardsDB::createConnection()’ to have static linkage. Any help?
I’m using Qt 4.7 with C++ inside Qt Creator if it helps.
When you define a
staticmember function separately from the declaration, you do not have to use thestaticmodifier.Also do you really mean to make every single function of your class
static? Your class represents a database of sorts forCardobjects, so I think you’d want to actually store member data with the class itself?Even in that snippet above, you create a
QSqlDatabaseobject, butdb‘s existence is only the extent of thecreateConnection()function.