Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to connect Serwer application and Client Application



  • 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.";

    }



  • @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.


Log in to reply