Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to connect Serwer application and Client Application

How to connect Serwer application and Client Application

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 233 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    coutKateM
    wrote on last edited by
    #1

    I have Serwer application connected to a database like that:

    Database::Database(QObject *parent) : QObject(parent)
    {
    db = QSqlDatabase::addDatabase("QPSQL");
    db.setHostName("localhost");
    db.setDatabaseName("main");
    db.setUserName("postgres");
    db.setPort(5432);
    db.setPassword("zalfon19");
    if(!db.open()){
    auto problemDialog = new InfoDialog(InfoDialog::Warning, "Baza danych", "Aplikacja napotkała na problem z połączeniem z bazą danych", nullptr, true);
    problemDialog->show();
    qDebug()<<"There is a problem with database.";
    return;
    }
    qDebug()<<"There is no problem with database.";

    QSqlQuery querry;
    querry.exec("truncate active_errors");
    

    }

    The client application, without necessary changes, just for explanation my situation :

    Database::Database(QObject *parent) : QObject(parent)
    {
    db = QSqlDatabase::addDatabase("QPSQL");
    db.setHostName(settings.dbpath.get());
    db.setDatabaseName("main");
    db.setUserName("postgres");
    db.setPort(5432);
    db.setPassword("zalfon19");
    if(!db.open()){
    auto problemDialog = new InfoDialog(InfoDialog::Warning, "Baza danych", "Aplikacja napotkała na problem z połączeniem z bazą danych", nullptr, true);
    problemDialog->show();
    qDebug()<<"There is a problem with database.";
    }
    qDebug()<<"There is no problem with database.";

    }

    JonBJ 1 Reply Last reply
    0
    • C coutKateM

      I have Serwer application connected to a database like that:

      Database::Database(QObject *parent) : QObject(parent)
      {
      db = QSqlDatabase::addDatabase("QPSQL");
      db.setHostName("localhost");
      db.setDatabaseName("main");
      db.setUserName("postgres");
      db.setPort(5432);
      db.setPassword("zalfon19");
      if(!db.open()){
      auto problemDialog = new InfoDialog(InfoDialog::Warning, "Baza danych", "Aplikacja napotkała na problem z połączeniem z bazą danych", nullptr, true);
      problemDialog->show();
      qDebug()<<"There is a problem with database.";
      return;
      }
      qDebug()<<"There is no problem with database.";

      QSqlQuery querry;
      querry.exec("truncate active_errors");
      

      }

      The client application, without necessary changes, just for explanation my situation :

      Database::Database(QObject *parent) : QObject(parent)
      {
      db = QSqlDatabase::addDatabase("QPSQL");
      db.setHostName(settings.dbpath.get());
      db.setDatabaseName("main");
      db.setUserName("postgres");
      db.setPort(5432);
      db.setPassword("zalfon19");
      if(!db.open()){
      auto problemDialog = new InfoDialog(InfoDialog::Warning, "Baza danych", "Aplikacja napotkała na problem z połączeniem z bazą danych", nullptr, true);
      problemDialog->show();
      qDebug()<<"There is a problem with database.";
      }
      qDebug()<<"There is no problem with database.";

      }

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @coutKateM

      • You do not say what error you get, if any. We are not mind-readers.

      • For all we know, maybe the path is wrong, or the database name, or the credentials. When a QSqlDatabase operation fails there is QSqlDatabase::lastError(), which you should obviously be accessing.

      • You seem to have a member variable of db. As the docs state, you should not have any member variable of type QSqlDatabase around.

      • You talk about "server" & "client". Yet they both access the database directly. No idea what you mean by "server/client" here.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved