bool MainWindow::connectToDB()
{
db.setHostName("localhost");
db.setDatabaseName("lernit");
db.setUserName("admin");
db.setPassword("admin");
if(!db.open())
{
QMessageBox::information(this,
"LenrIT",db.
lastError().
text());
}
else
{
QSqlQuery select
("SELECT language1, language2, plural, description FROM words_tbl");
while(select.next())
{
QString language1
= select.
value(0).
toString();
QString language2
= select.
value(1).
toString();
QString plural
= select.
value(2).
toString();
QString description
= select.
value(3).
toString();
db2.setDatabaseName("LernIT.db");
if(!db2.open())
QMessageBox::information(this,
"LenrIT",db.
lastError().
text());
insert.prepare("insert into words_tbl (language1, language2, plural, description) values ('"
+ language1 + "', '" + language2 + "', '" + plural + "', '" + description + "')");
if( ! insert.exec() )
QMessageBox::information(this,
"LernIT",insert.
lastError().
text());
db.setHostName("localhost");
db.setDatabaseName("lernit");
db.setUserName("admin");
db.setPassword("admin");
if(!db.open())
QMessageBox::information(this,
"LenrIT",db.
lastError().
text());
}
}
}
bool MainWindow::connectToDB()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("lernit");
db.setUserName("admin");
db.setPassword("admin");
if(!db.open())
{
QMessageBox::information(this,"LenrIT",db.lastError().text());
}
else
{
QSqlQuery select("SELECT language1, language2, plural, description FROM words_tbl");
while(select.next())
{
QString language1 = select.value(0).toString();
QString language2 = select.value(1).toString();
QString plural = select.value(2).toString();
QString description = select.value(3).toString();
QSqlDatabase db2 = QSqlDatabase::addDatabase("QSQLITE");
db2.setDatabaseName("LernIT.db");
if(!db2.open())
QMessageBox::information(this,"LenrIT",db.lastError().text());
QSqlQuery insert;
insert.prepare("insert into words_tbl (language1, language2, plural, description) values ('"
+ language1 + "', '" + language2 + "', '" + plural + "', '" + description + "')");
if( ! insert.exec() )
QMessageBox::information(this,"LernIT",insert.lastError().text());
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("lernit");
db.setUserName("admin");
db.setPassword("admin");
if(!db.open())
QMessageBox::information(this,"LenrIT",db.lastError().text());
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks