@@ -29,6 +29,7 @@ extern "C"
29
29
30
30
#include " qgsconnectiondialog.h"
31
31
#include " qgsmessageviewer.h"
32
+ #include " qgsdatasourceuri.h"
32
33
33
34
QgsConnectionDialog::QgsConnectionDialog (QWidget *parent, const QString& connName, Qt::WFlags fl)
34
35
: QDialog(parent, fl)
@@ -62,17 +63,17 @@ QgsConnectionDialog::~QgsConnectionDialog()
62
63
63
64
void QgsConnectionDialog::testConnection ()
64
65
{
65
- QString connInfo = " host=" + txtHost->text () + " dbname=" + txtDatabase->text () +
66
- " port=" + txtPort->text () + " user=" + txtUsername->text () + " password=" + txtPassword->text ();
67
- PGconn *pd = PQconnectdb ((const char *) connInfo);
66
+ QgsDataSourceURI uri;
67
+ uri.setConnection ( txtHost->text (), txtPort->text (), txtDatabase->text (), txtUsername->text (), txtPassword->text () );
68
+ PGconn *pd = PQconnectdb ((const char *) uri.connInfo () );
69
+
70
+ if (PQstatus (pd) == CONNECTION_OK) {
71
+ // Database successfully opened; we can now issue SQL commands.
72
+ QMessageBox::information (this , tr (" Test connection" ), tr (" Connection to " ) + txtDatabase->text () + tr (" was successfull" ));
73
+ } else {
74
+ QMessageBox::information (this , tr (" Test connection" ), tr (" Connection failed - Check settings and try again " ));
75
+ }
68
76
69
- if (PQstatus (pd) == CONNECTION_OK) {
70
- // Database successfully opened; we can now issue SQL commands.
71
- QMessageBox::information (this , tr (" Test connection" ), tr (" Connection to " ) + txtDatabase->text () + tr (" was successfull" ));
72
- } else {
73
- QMessageBox::information (this , tr (" Test connection" ), tr (" Connection failed - Check settings and try again " ));
74
- }
75
-
76
77
PQfinish (pd);
77
78
}
78
79
0 commit comments