Thank you for your help so far.
My SQL_BSP.pro now looks like this:
QT += core gui
QT += sql
TARGET = SQL_BSP
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
OTHER_FILES += \
libpq.lib
QT += core gui
QT += sql
TARGET = SQL_BSP
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
OTHER_FILES += \
libpq.lib
To copy to clipboard, switch view to plain text mode
I tried to get access to the sql db like this:
#include <QtSql>
#include <QSqlError>
#include <QSqlDriver>
#include <QSqlDriverPlugin>
dbAlex.setHostName("localhost");
dbAlex.setPort(5433);
dbAlex.setUserName("postgres");
dbAlex.setPassword("***");
dbAlex.setDatabaseName("QT");
dbAlex.open("postgres", "***");
if (dbAlex.isOpen() == true)
m_sConnState = "true";
else
m_sConnState = "false";
m_sConnState = dbError.text();
ui->lineEdit->setText(m_sConnState);
#include <QtSql>
#include <QSqlError>
#include <QSqlDriver>
#include <QSqlDriverPlugin>
QSqlDatabase dbAlex = QSqlDatabase::addDatabase("QPSQL");
dbAlex.setHostName("localhost");
dbAlex.setPort(5433);
dbAlex.setUserName("postgres");
dbAlex.setPassword("***");
dbAlex.setDatabaseName("QT");
dbAlex.open("postgres", "***");
if (dbAlex.isOpen() == true)
m_sConnState = "true";
else
m_sConnState = "false";
QSqlError dbError = dbAlex.lastError();
m_sConnState = dbError.text();
ui->lineEdit->setText(m_sConnState);
To copy to clipboard, switch view to plain text mode
The message in my lineEdit now is "driver not loaded".
I now, I habe to work with QSqlDriver and QSqlDriverPlugin, but I have no idea how.
Bookmarks