Client crashes if there is no QApplication::exec() call

Forum for posting problems using QxOrm library

Client crashes if there is no QApplication::exec() call

Postby nickla » Thu Aug 09, 2012 6:12 pm

I develop client side of my system.

There is authorization window in my program. This window must be shown before main window and if user fails with authentication - main window will not be shown.

This is my main.cpp:
Code: Select all
#include <QtGui/QApplication>

#include "mainwindow.h"
#include "dialoglogin.h"

#include <QxMemLeak.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;

    QSettings * settings = new QSettings("config.ini", QSettings::IniFormat);
    qx::service::QxConnect::getSingleton()->setIp(settings->value("general/host", "localhost").toString());
    qx::service::QxConnect::getSingleton()->setPort(settings->value("general/port", 21212).toInt());

    // We will call authentication dialog window here
    DialogLogin login;
    if (login.exec() == 0) {
        // if user denied we will close application
        exit(0);
    }

#if defined(QX_TAXICLIENT_MAXIMIZED)
    w.showMaximized();
#else
    w.show();
#endif
   
    return a.exec();
}


This is my auth window code. Header:
Code: Select all
#ifndef DIALOGLOGIN_H
#define DIALOGLOGIN_H

#include <QDialog>

namespace Ui {
class DialogLogin;
}

class DialogLogin : public QDialog
{
    Q_OBJECT
   
public:
    DialogLogin(QWidget *parent = 0);
    ~DialogLogin();
   
protected Q_SLOTS:
    void onLoginClick();

private:
    Ui::DialogLogin *ui;

};

#endif // DIALOGLOGIN_H


CPP file:
Code: Select all
#include "dialoglogin.h"
#include "ui_dialoglogin.h"

#include <QMessageBox>

#include "../../qxService/include/service/phoneservice.h"
#include "../../qxService/include/service/userservice.h"

#include <QxMemLeak.h>

DialogLogin::DialogLogin(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogLogin)
{
    ui->setupUi(this);
    connect(ui->pushLogin, SIGNAL(clicked()), this, SLOT(onLoginClick()));
}

DialogLogin::~DialogLogin()
{
    delete ui;
}

void DialogLogin::onLoginClick()
{
    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

    // Create input parameters
    UserServiceInputPtr input = UserServiceInputPtr(new UserServiceInput());
    input->setUsername(ui->lineUsername->text());
    input->setPassword(ui->linePassword->text());

    // Create service to call and set input parameters
    UserService service;
    service.setInputParameter(input);
    service.fetchById();

    // If transaction is ok => display user fetched on GUI
    UserPtr output = (service.isValidWithOutput() ? service.getOutputParameter()->user() : UserPtr());

    qDebug() << qx::serialization::xml::to_string(* service.getTransaction());

    QApplication::restoreOverrideCursor();
}


Problem is following. If i try to authenticate and after that i`ll close window (application will exit too) i`ll receive error.
ASSERT failure in QMutex::lock: "Internal error, infinite wait has timed out.", file thread\qmutex.cpp, line 166


But if i change main.cpp code like this:
Code: Select all
#include <QtGui/QApplication>

#include "mainwindow.h"
#include "dialoglogin.h"

#include <QxMemLeak.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;

    QSettings * settings = new QSettings("config.ini", QSettings::IniFormat);
    qx::service::QxConnect::getSingleton()->setIp(settings->value("general/host", "localhost").toString());
    qx::service::QxConnect::getSingleton()->setPort(settings->value("general/port", 21212).toInt());

    // We will call authentication dialog window here
    DialogLogin login;
    if (login.exec() == 0) {
        // if user denied we will close application
        // exit(0); I DELETED THIS AND WE WILL NOT EXIT APPLICATION IF USER DENIED
    }

#if defined(QX_TAXICLIENT_MAXIMIZED)
    w.showMaximized();
#else
    w.show();
#endif
   
    return a.exec();
}


Everything is ok even after i close main window.
nickla
 
Posts: 52
Joined: Wed Jul 11, 2012 4:19 pm
Location: Russia

Re: Client crashes if there is no QApplication::exec() call

Postby qxorm » Fri Aug 10, 2012 9:39 am

Maybe you could try to replace exit(0); by return a.exec();.
I think it should work...
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Client crashes if there is no QApplication::exec() call

Postby nickla » Sun Aug 12, 2012 9:19 am

I dont think that it is right. Anyway, i found this in QT help QApplication::exec :

Generally, no user interaction can take place before calling exec(). As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widgets call exec() to start a local event loop.


I think that it is wrong decision to do like that before QApplication::exec(). I show autherntication windows on show event of main window. Works great.
nickla
 
Posts: 52
Joined: Wed Jul 11, 2012 4:19 pm
Location: Russia


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 5 guests

cron