SHARE
TWEET

File .cpp Proyek Test Koneksi QT C++ PostgreSQL

stevennathaniel Apr 30th, 2016 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <QCoreApplication>
  2. #include <QSql>
  3. #include <QSqlDatabase>
  4. #include <QDebug>
  5. #include <QSqlError>
  6.  
  7. // int database::nconnect(QString servername, QString dbname);
  8.  
  9. int main(int argc, char *argv[])
  10.  
  11.  
  12. {
  13.     QCoreApplication a(argc, argv);
  14.  
  15. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
  16.  
  17. db.setHostName("localhost");
  18.  
  19. db.setDatabaseName("balikpapan");
  20.  
  21. db.setUserName("steven");
  22.  
  23. db.setPassword("kucing");
  24.  
  25. db.setPort(5432);
  26.  
  27. if(db.open())
  28.  
  29. {
  30.  
  31.     qDebug() << "Open";
  32.     db.close();
  33.  
  34. }
  35.  
  36.  
  37. else
  38.  
  39. {
  40.  
  41. qDebug() << "Error = " << db.lastError().text();
  42.  
  43. }
  44.  
  45.  
  46.  
  47.     return a.exec();
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top