Qt - Perform an action when a dialog is loaded

Asked

Viewed 31 times

0

I have an application that serves to manage a barracks of my city, on the sniper registration screen I would like to check before if there is a class registered in the database, if not close the dialog, I tried to do this way:

void CadastrarAtirador::showEvent(QShowEvent *ev)
{
    QDialog::showEvent(ev);
    if(turma->anos().isEmpty()){
        this->close();
    }
}

The error message for the user is displayed normally, but then a blank dialog is shown and when it is closed the program launches an assert:

Falha ao recuperar os anos:  QSqlError("42P01", "QPSQL: Unable to create query", "ERROR:  relation \"sch_tg.va_turma\" does not exist\nLINE 1: SELECT ano FROM sch_tg.va_turma\n                        ^\n(42P01)")
Falha ao recuperar os anos:  QSqlError("42P01", "QPSQL: Unable to create query", "ERROR:  relation \"sch_tg.va_turma\" does not exist\nLINE 1: SELECT ano FROM sch_tg.va_turma\n                        ^\n(42P01)")
ASSERT: "platformWindow" in file qwindowscontext.cpp, line 1149
09:40:19: The program has unexpectedly finished.
09:40:19: The process was ended forcefully.
  • Apparently it is an error in the query you are doing to check if there is a registered class. Check if "sch_tg.va_turma" is a table in your bank.

  • @J.PedroA. This is obvious, the user first needs to create a class, the years() method serves to execute a select, and if there is nothing it does not fill the Qstringlist, then this empty, so if it is empty (ie there is no this table yet) it shows an error during the constructor, and when finished loading the dialog, if there is nothing in the database it should close the dialog, at least it should work like this.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.