Hi guys,
Using singleton was a good idea, I use in class TraderProc and the result is we still have application locked, see what happens when I logoff, the application hangs. Below the code:
In main.cpp:
#include <QApplication>
#include <QCoreApplication>
#include "TraderProc.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(trader);
QT_REQUIRE_VERSION(argc, argv, "4.3.4");
QTimer::singleShot(0, TraderProc
::TrProc(),
SLOT(startLogin
()));
return app.exec();
}
#include <QApplication>
#include <QCoreApplication>
#include "TraderProc.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(trader);
QT_REQUIRE_VERSION(argc, argv, "4.3.4");
QApplication app(argc, argv);
QTimer::singleShot(0, TraderProc::TrProc(), SLOT(startLogin()));
return app.exec();
}
To copy to clipboard, switch view to plain text mode
In TraderProc.h:
#include <QObject>
#include <QCoreApplication>
#include <QTimer>
#include "engine/Login.h"
#include "MainWindow.h"
class Login;
class MainWindow;
{
Q_OBJECT
public:
static TraderProc *TrProc();
private:
TraderProc();
static TraderProc *_TrProc;
bool isLogin;
void openTrader(bool );
public slots:
void startLogin();
protected:
};
#endif
#include <QObject>
#include <QCoreApplication>
#include <QTimer>
#include "engine/Login.h"
#include "MainWindow.h"
class Login;
class MainWindow;
class TraderProc: public QObject
{
Q_OBJECT
public:
static TraderProc *TrProc();
private:
TraderProc();
static TraderProc *_TrProc;
bool isLogin;
void openTrader(bool );
public slots:
void startLogin();
protected:
};
#endif
To copy to clipboard, switch view to plain text mode
In TraderProc.cpp
#include "TraderProc.h"
TraderProc *TraderProc::_TrProc = 0;
TraderProc *TraderProc::TrProc()
{
if (_TrProc == 0)
_TrProc = new TraderProc;
return _TrProc;
}
TraderProc::TraderProc()
:isLogin(false)
{
}
void TraderProc::startLogin()
{
Login login;
int l = login.exec();
{
isLogin = true;
}
else
{
isLogin = false;
}
openTrader(isLogin);
}
void TraderProc::openTrader(bool log)
{
if (log)
{
MainWindow *mainWin = new MainWindow;
mainWin->show();
}
else
{
exit(0);
}
}
#include "TraderProc.h"
TraderProc *TraderProc::_TrProc = 0;
TraderProc *TraderProc::TrProc()
{
if (_TrProc == 0)
_TrProc = new TraderProc;
return _TrProc;
}
TraderProc::TraderProc()
:isLogin(false)
{
}
void TraderProc::startLogin()
{
Login login;
int l = login.exec();
if (l == QDialog::Accepted)
{
isLogin = true;
}
else
{
isLogin = false;
}
openTrader(isLogin);
}
void TraderProc::openTrader(bool log)
{
if (log)
{
MainWindow *mainWin = new MainWindow;
mainWin->show();
}
else
{
exit(0);
}
}
To copy to clipboard, switch view to plain text mode
In MainWindow.cpp
...
void MainWindow::logoff()
{
close();
QTimer::singleShot(0, TraderProc
::TrProc(),
SLOT(startLogin
()));
}
...
...
void MainWindow::logoff()
{
close();
QTimer::singleShot(0, TraderProc::TrProc(), SLOT(startLogin()));
}
...
To copy to clipboard, switch view to plain text mode
Thanks for help.
Marcelo E. Geyer
Bookmarks