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.