Code: Alles auswählen
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("mudmania.db");
// set Username, Pasword, Hostname alles auch schon probiert.
if (! db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"MUDmania needs SQLite support, but the database\n"
"plugin of your Qt is not available.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel, QMessageBox::NoButton);
}
if (db.isOpenError()) {
QMessageBox::information(0, "MUDmania DB error 1", db.lastError().text());
}
if (! db.isValid()) {
QMessageBox::information(0, "MUDmania DB", "error 2");
}
QSqlQuery query("select * from worlds");
// AUch schon so probiert:
//QSqlQuery query("select * from worlds", db);
if (! db.isOpen()) {
QMessageBox::information(this, "mm", "open err");
}
if (! query.exec()) {
QMessageBox::information(this, "mm", "exec");
}
if (! query.isActive()) {
QMessageBox::information(this, "mm", "not active");
}
if (! query.isValid()) {
//QMessageBox::information(this, "mm", "not valid");
}
// Hier kommt ein Leerstring raus !!!
QMessageBox::information(this, "mm tables", db.tables().join(" "));
// Und hier gibt's eine -1 zurück. War nicht anders zu erwarten...
QMessageBox::information(this, "mm size", QString::number(query.size()));
int i = query.record().indexOf("name");
while (query.next()) {
QString str = query.value(i).toString();
QMessageBox::information(this, "data", str);
new QListWidgetItem(str, m_list);
}
Die DB wird gefunden. Format SQL3. Ist sie nicht vorhanden, legt er an der Stelle eine leere DB an. Also wird der Pfad ok sein.
Kenn jemand ein gutes Beispiel, wie man Sqlite unter Qt programmiert? Abgesehen von den Examples.
Ich benutze die MinGW-Qt Version unter Windows. Kann es daran liegen?
Viele Grüße,
E*