Qt PostgreSQL 範例
=== 測試環境
OS: Windows 7
Qt Verstion: 5.5.0
Compiler: Visual Studio 2013
OS: Arch Linux 4.1.6
Qt Version: 5.5.0
Compiler: GCC 5.2.0
=== 程式範例
=== 錯誤訊息
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
在 Windows,確認下列檔案
MyAppDir\sqldrivers\qsqlpsql.dll
MyAppDir\libpq.dll
MyAppDir\libeay32.dll
MyAppDir\ssleay32.dll
在 linux,確認 qt project file 加上
INCLUDEPATH+=/usr/include/pgsql
LIBS+=-L/usr/lib -lpq
=== 資料來源
Qt Documentation - SQL Database Drivers
http://doc.qt.io/qt-5/sql-driver.html
Qt: SELECT-Query to PostgreSQL-Server always responses with NULL
http://stackoverflow.com/questions/13633055/qt-select-query-to-postgresql-server-always-responses-with-null
QT5: Failed to load psql driver in windows
http://stackoverflow.com/questions/20884010/qt5-failed-to-load-psql-driver-in-windows
2015年10月1日 星期四
2015年9月26日 星期六
Arch 安裝 PostgreSQL
第一步先安裝 PostgreSQL
sudo pacman -S postgresql
然後登入 postgres 帳號
sudo -i -u postgres
接著進行資料庫初始化
initdb --locale en_US.UTF-8 -E UTF8 -D '/var/lib/postgres/data'
如果發生錯誤,表示目前的 locale 不是 en_US.UTF-8
initdb: invalid locale name "en_US.UTF-8"
初始化資料庫後就可以啟動 PostgreSQL
sudo systemctl start postgresql.service
sudo systemctl enable postgresql.service
建立使用者
createuser --interactive
接著用剛剛建立的使用者帳號建立資料庫
createdb myDatabaseName
使用 psql 進入資料庫
psql -d myDatabaseName
允許遠端連線
修改 /var/lib/postgres/data/postgresql.conf 的內容
listen_addresses = '*'
接著在 /var/lib/postgres/data/pg_hba.conf 將原本的 IPv4設定為
host all all my_remote_client_ip_address/32 md5
設定完之後,重新啟動 PostgreSQL
sudo systemctl restart postgresql
資料來源:
Archlinux Wiki - PostgreSQL
https://wiki.archlinux.org/index.php/PostgreSQL
sudo pacman -S postgresql
然後登入 postgres 帳號
sudo -i -u postgres
接著進行資料庫初始化
initdb --locale en_US.UTF-8 -E UTF8 -D '/var/lib/postgres/data'
如果發生錯誤,表示目前的 locale 不是 en_US.UTF-8
initdb: invalid locale name "en_US.UTF-8"
初始化資料庫後就可以啟動 PostgreSQL
sudo systemctl start postgresql.service
sudo systemctl enable postgresql.service
建立使用者
createuser --interactive
接著用剛剛建立的使用者帳號建立資料庫
createdb myDatabaseName
使用 psql 進入資料庫
psql -d myDatabaseName
允許遠端連線
修改 /var/lib/postgres/data/postgresql.conf 的內容
listen_addresses = '*'
接著在 /var/lib/postgres/data/pg_hba.conf 將原本的 IPv4設定為
host all all my_remote_client_ip_address/32 md5
設定完之後,重新啟動 PostgreSQL
sudo systemctl restart postgresql
資料來源:
Archlinux Wiki - PostgreSQL
https://wiki.archlinux.org/index.php/PostgreSQL
訂閱:
文章 (Atom)