Qsqldatabase problem
Verfasst: 4. November 2008 17:13
hallo,
versuche gerade ein kleines programm mit hilfe eines tutorials zu schreiben, welches mir zugriff auf meine hier local installierte sql datenbank erlaubt.
dafür habe ich eine connection.h datei erstellt (so ähnlich ist sie im tutorial):
included wird sie dann in die main.cpp:
beim compilieren bekomm ich jedoch die fehlermeldung:
was mache ich falsch?
versuche gerade ein kleines programm mit hilfe eines tutorials zu schreiben, welches mir zugriff auf meine hier local installierte sql datenbank erlaubt.
dafür habe ich eine connection.h datei erstellt (so ähnlich ist sie im tutorial):
Code: Alles auswählen
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMessageBox>
#include <QSql>
class QSqlDatabase;
/*
This file defines a helper function to open a connection to an
in-memory SQLITE database and to create a test table.
If you want to use another database, simply modify the code
below. All the examples in this directory use this function to
connect to a database.
*/
//! [0]
static bool createConnection () {
QSqlDatabase db;
db = QSqlDatabase::addDatabase ("QMYSQL");
db -> setHostName ("localhost");
db -> setDatabaseName ("aubing");
db -> setUserName ("root");
db -> setPassword ("passowort");
if (!db.open ()) {
QMessageBox::critical (0, qApp -> tr ("cannot open database"), qApp -> tr ("unable to establish a database connection", QMessageBox::Cancel);
return false;
}
return true;
}
#endifCode: Alles auswählen
#include <QApplication>
#include "connection.h"
#include "tableeditor.h"
int main (int argc, char *argv[]) {
QApplication app (argc, argv);
if (!createConnection ())
return 1;
TableEditor editor ("user-message");
editor.show ();
return editor.exec ();
}Code: Alles auswählen
aggregate "SqlDatabase db" has incomplete type and cannot be defined