Fix bug, about application collapse by
db can't connect
This commit is contained in:
@@ -10,6 +10,8 @@ ADD_APP_VALUE(InProcessing)\
|
|||||||
ADD_APP_VALUE(LastOperationTime)\
|
ADD_APP_VALUE(LastOperationTime)\
|
||||||
ADD_APP_VALUE(LastOperation)\
|
ADD_APP_VALUE(LastOperation)\
|
||||||
ADD_APP_VALUE(EmptyScanFlag)\
|
ADD_APP_VALUE(EmptyScanFlag)\
|
||||||
|
ADD_APP_VALUE(DBconnected)\
|
||||||
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ bool SQLHelper::Open() {
|
|||||||
defaultDatabase->setDatabaseName("USCT"); // 数据库名称
|
defaultDatabase->setDatabaseName("USCT"); // 数据库名称
|
||||||
defaultDatabase->setUserName("rc"); // 数据库用户名
|
defaultDatabase->setUserName("rc"); // 数据库用户名
|
||||||
defaultDatabase->setPassword("123$%^"); // 数据库密码
|
defaultDatabase->setPassword("123$%^"); // 数据库密码
|
||||||
return defaultDatabase->open();
|
bool ret = defaultDatabase->open();
|
||||||
|
if (!ret){
|
||||||
|
delete defaultDatabase;
|
||||||
|
defaultDatabase = nullptr;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SQLHelper::Open(QSqlDatabase *base) {
|
bool SQLHelper::Open(QSqlDatabase *base) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#define ADD_EVENT()\
|
#define ADD_EVENT()\
|
||||||
ADD_EVENT_VALUE(RequestLogin)\
|
ADD_EVENT_VALUE(RequestLogin)\
|
||||||
|
ADD_EVENT_VALUE(LoginSuccess)\
|
||||||
ADD_EVENT_VALUE(RequestShutdown)\
|
ADD_EVENT_VALUE(RequestShutdown)\
|
||||||
ADD_EVENT_VALUE(LoginRoleChanged)\
|
ADD_EVENT_VALUE(LoginRoleChanged)\
|
||||||
ADD_EVENT_VALUE(PatientSelected)\
|
ADD_EVENT_VALUE(PatientSelected)\
|
||||||
|
|||||||
43
src/main.cpp
43
src/main.cpp
@@ -18,6 +18,7 @@
|
|||||||
#include "src/utilities/LanguageSwitcher.h"
|
#include "src/utilities/LanguageSwitcher.h"
|
||||||
#include "utilities/TouchScreenSignalSender.h"
|
#include "utilities/TouchScreenSignalSender.h"
|
||||||
#include "keyboard/KeyboardManager.h"
|
#include "keyboard/KeyboardManager.h"
|
||||||
|
#include "appvals/AppGlobalValues.h"
|
||||||
|
|
||||||
QString loadFontFromFile(QString path)
|
QString loadFontFromFile(QString path)
|
||||||
{
|
{
|
||||||
@@ -74,14 +75,7 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
a.setStyleSheet(QLatin1String(file.readAll()));
|
a.setStyleSheet(QLatin1String(file.readAll()));
|
||||||
}
|
}
|
||||||
|
AppGlobalValues::setDBconnected(false);
|
||||||
|
|
||||||
bool sqlConnected= SQLHelper::Open();
|
|
||||||
if (!sqlConnected)
|
|
||||||
{
|
|
||||||
//TODO: 数据库连接失败错误
|
|
||||||
exit(-99);
|
|
||||||
}
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
DialogManager::Default()->init(&w);
|
DialogManager::Default()->init(&w);
|
||||||
UserOperationLog::Default()->init();
|
UserOperationLog::Default()->init();
|
||||||
@@ -98,37 +92,10 @@ int main(int argc, char* argv[])
|
|||||||
KeyboardManager::getInstance();
|
KeyboardManager::getInstance();
|
||||||
UserOperationLog::cleanHistoryLog();
|
UserOperationLog::cleanHistoryLog();
|
||||||
|
|
||||||
if (app_args.contains("-d"))
|
w.showFullScreen();
|
||||||
//if (true)
|
DeviceManager::Default()->initDevice();
|
||||||
{
|
|
||||||
|
|
||||||
w.debugConsoleOn();
|
ret = a.exec();
|
||||||
w.showFullScreen();
|
|
||||||
|
|
||||||
qInstallMessageHandler(MainWindow::QMessageOutput);
|
|
||||||
QThread thread;
|
|
||||||
StdOutRedirector redir;
|
|
||||||
redir.setOutputTF(w.getEdit());
|
|
||||||
QTimer Timer;
|
|
||||||
redir.moveToThread(&thread);
|
|
||||||
QObject::connect(&Timer, SIGNAL(timeout()), &redir, SLOT(readOutsToTF()));
|
|
||||||
fflush(stdout);
|
|
||||||
Timer.start(1000);
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
DeviceManager::Default()->initDevice();
|
|
||||||
|
|
||||||
ret = a.exec();
|
|
||||||
thread.terminate();
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
w.showFullScreen();
|
|
||||||
DeviceManager::Default()->initDevice();
|
|
||||||
|
|
||||||
ret = a.exec();
|
|
||||||
}
|
|
||||||
DeviceManager::Default()->close();
|
DeviceManager::Default()->close();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
#include "log/UserOperationLog.h"
|
#include "log/UserOperationLog.h"
|
||||||
#include "json/jsonobject.h"
|
#include "json/jsonobject.h"
|
||||||
#include "components/ULineEdit.h"
|
#include "components/ULineEdit.h"
|
||||||
|
#include "appvals/AppGlobalValues.h"
|
||||||
|
#include "db/SQLHelper.h"
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -158,6 +161,18 @@ void LoginDialog::clearInputData()
|
|||||||
|
|
||||||
void LoginDialog::doLogin()
|
void LoginDialog::doLogin()
|
||||||
{
|
{
|
||||||
|
if (!(AppGlobalValues::DBconnected().toBool())){
|
||||||
|
bool sqlConnected= SQLHelper::Open();
|
||||||
|
if (sqlConnected)
|
||||||
|
{
|
||||||
|
AppGlobalValues::setDBconnected(true);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
mErrorMessage->setText(QString(tr("Can't connect db. Please reboot the device and retry, or call for the service help.")).arg(LOGIN_LOCK_MINUTIES));
|
||||||
|
mErrorMessage->setVisible(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(mLoginFailedCount >= LOGIN_LOCK_COUNT)
|
if(mLoginFailedCount >= LOGIN_LOCK_COUNT)
|
||||||
{
|
{
|
||||||
mErrorMessage->setText(QString(tr("Login locked. Please retry after %1 minutes.")).arg(LOGIN_LOCK_MINUTIES));
|
mErrorMessage->setText(QString(tr("Login locked. Please retry after %1 minutes.")).arg(LOGIN_LOCK_MINUTIES));
|
||||||
@@ -176,6 +191,7 @@ void LoginDialog::doLogin()
|
|||||||
{
|
{
|
||||||
resetLoginFailedCount();
|
resetLoginFailedCount();
|
||||||
mErrorMessage->setVisible(false);
|
mErrorMessage->setVisible(false);
|
||||||
|
EventCenter::Default()->triggerEvent(GUIEvents::LoginSuccess,nullptr,nullptr);
|
||||||
accept();
|
accept();
|
||||||
LOG_USER_OPERATION("Login Sucessful");
|
LOG_USER_OPERATION("Login Sucessful");
|
||||||
JsonObject::Instance()->setDefaultUser(strUserCode);
|
JsonObject::Instance()->setDefaultUser(strUserCode);
|
||||||
|
|||||||
@@ -31,18 +31,17 @@ MainWindow::MainWindow(QWidget* aParent)
|
|||||||
: QMainWindow(aParent)
|
: QMainWindow(aParent)
|
||||||
, mUI(new Ui::MainWindow)
|
, mUI(new Ui::MainWindow)
|
||||||
, mDebugConsoleWidget(nullptr)
|
, mDebugConsoleWidget(nullptr)
|
||||||
, mDebugMessageConsole(nullptr)
|
|
||||||
, mTabWidget(new QTabWidget(this))
|
, mTabWidget(new QTabWidget(this))
|
||||||
, mInitializWidget(new InitializeWidget(this))
|
, mInitializWidget(new InitializeWidget(this))
|
||||||
, mShutdownWidget(new ShutdownWidget(nullptr))
|
, mShutdownWidget(new ShutdownWidget(nullptr))
|
||||||
, mAdminTabIndex(-1)
|
, mAdminTabIndex(-1)
|
||||||
, mThread(nullptr)
|
, mThread(nullptr)
|
||||||
, mIsDebugMode(false)
|
, mTabInited(false)
|
||||||
{
|
{
|
||||||
mUI->setupUi(this);
|
mUI->setupUi(this);
|
||||||
this->setWindowFlags(Qt::Window);
|
this->setWindowFlags(Qt::Window);
|
||||||
|
|
||||||
initializeTabWidget();
|
|
||||||
initializeLayout();
|
initializeLayout();
|
||||||
|
|
||||||
connect(EventCenter::Default(), &EventCenter::PatientSelected, this,&MainWindow::switchToScanTab);
|
connect(EventCenter::Default(), &EventCenter::PatientSelected, this,&MainWindow::switchToScanTab);
|
||||||
@@ -59,8 +58,18 @@ MainWindow::MainWindow(QWidget* aParent)
|
|||||||
connect(DialogManager::Default(), &DialogManager::loginDialogShown, this, [this]()
|
connect(DialogManager::Default(), &DialogManager::loginDialogShown, this, [this]()
|
||||||
{
|
{
|
||||||
mInitializWidget->setVisible(false);
|
mInitializWidget->setVisible(false);
|
||||||
|
|
||||||
|
});
|
||||||
|
connect(EventCenter::Default(), &EventCenter::LoginSuccess, this, [this]()
|
||||||
|
{
|
||||||
|
if(!mTabInited){
|
||||||
|
mTabInited = true;
|
||||||
|
initializeTabWidget();
|
||||||
|
mTabWidget->setCurrentIndex(0);
|
||||||
|
}
|
||||||
mTabWidget->setVisible(true);
|
mTabWidget->setVisible(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
GUIErrorHandle::Default()->init();
|
GUIErrorHandle::Default()->init();
|
||||||
QApplication::setActiveWindow(centralWidget());
|
QApplication::setActiveWindow(centralWidget());
|
||||||
}
|
}
|
||||||
@@ -105,13 +114,14 @@ void MainWindow::initializeTabWidget()
|
|||||||
{
|
{
|
||||||
mTabWidget->setTabPosition(QTabWidget::South);
|
mTabWidget->setTabPosition(QTabWidget::South);
|
||||||
mTabWidget->setContentsMargins(0, 0, 0, 0);
|
mTabWidget->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
auto selectForm = new SelectFormWidget(this);
|
|
||||||
mTabWidget->addTab(selectForm, tr("Select"));
|
|
||||||
auto scanForm = new ScanFormWidget(this);
|
|
||||||
mTabWidget->addTab(scanForm, tr("Scan"));
|
|
||||||
auto verifyForm = new ReconFormWidget(this);
|
auto verifyForm = new ReconFormWidget(this);
|
||||||
mTabWidget->addTab(verifyForm, tr("Recon"));
|
mTabWidget->insertTab(0,verifyForm, tr("Recon"));
|
||||||
|
auto scanForm = new ScanFormWidget(this);
|
||||||
|
mTabWidget->insertTab(0,scanForm, tr("Scan"));
|
||||||
|
auto selectForm = new SelectFormWidget(this);
|
||||||
|
mTabWidget->insertTab(0,selectForm, tr("Select"));
|
||||||
|
|
||||||
|
|
||||||
mTabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
mTabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,36 +261,6 @@ void MainWindow::swipeTriggered(QSwipeGesture* aSwipeGesture)
|
|||||||
{
|
{
|
||||||
if (aSwipeGesture->state() == Qt::GestureFinished)
|
if (aSwipeGesture->state() == Qt::GestureFinished)
|
||||||
{
|
{
|
||||||
//if (gesture->horizontalDirection() == QSwipeGesture::Right) {
|
|
||||||
// int index = tab->currentIndex();
|
|
||||||
// index--;
|
|
||||||
// if (index >= 0) {
|
|
||||||
// tab->setCurrentIndex(index);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//}
|
|
||||||
//if (gesture->horizontalDirection() == QSwipeGesture::Left) {
|
|
||||||
// int index = tab->currentIndex();
|
|
||||||
// index++;
|
|
||||||
// if (index < tab->count()) {
|
|
||||||
// tab->setCurrentIndex(index);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
if (aSwipeGesture->verticalDirection() == QSwipeGesture::Down)
|
|
||||||
{
|
|
||||||
if (mIsDebugMode)
|
|
||||||
{
|
|
||||||
mDebugConsoleWidget->show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (aSwipeGesture->verticalDirection() == QSwipeGesture::Up)
|
|
||||||
{
|
|
||||||
if (mIsDebugMode)
|
|
||||||
{
|
|
||||||
mDebugConsoleWidget->hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,55 +296,3 @@ void MainWindow::resetRoleLayout() {
|
|||||||
}
|
}
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
//------log out about----------------------------------------------------------
|
|
||||||
|
|
||||||
QTextEdit* MainWindow::getEdit()
|
|
||||||
{
|
|
||||||
return mDebugMessageConsole;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::debugConsoleOn()
|
|
||||||
{
|
|
||||||
mIsDebugMode = true;
|
|
||||||
mDebugConsoleWidget = new QDockWidget(this);
|
|
||||||
mDebugConsoleWidget->setObjectName(QString::fromUtf8("dockWidget"));
|
|
||||||
mDebugConsoleWidget->setAllowedAreas(Qt::RightDockWidgetArea);
|
|
||||||
this->addDockWidget(static_cast<Qt::DockWidgetArea>(2), mDebugConsoleWidget);
|
|
||||||
|
|
||||||
mDebugMessageConsole = new UTextEdit(this);
|
|
||||||
mDebugMessageConsole->setFocusPolicy(Qt::NoFocus);
|
|
||||||
mDebugConsoleWidget->setWidget(mDebugMessageConsole);
|
|
||||||
|
|
||||||
const QString edit_style =
|
|
||||||
"QScrollBar:vertical{border: 0px solid grey; background:#2d2d2d; width: 15px; margin: 0px 0 0px 0; }"
|
|
||||||
"QScrollBar::handle:vertical{background:#5a5a5a;min-height: 25px;}"
|
|
||||||
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical{background:#2d2d2d;}";
|
|
||||||
mDebugMessageConsole->verticalScrollBar()->setStyleSheet(edit_style);
|
|
||||||
//clear buffer before redirect;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::QMessageOutput(QtMsgType aType, const QMessageLogContext& aContext, const QString& msg)
|
|
||||||
{
|
|
||||||
|
|
||||||
std::cout << msg.toStdString().c_str() << std::endl;
|
|
||||||
|
|
||||||
//QByteArray localMsg = msg.toLocal8Bit();
|
|
||||||
//switch (type) {
|
|
||||||
//case QtDebugMsg:
|
|
||||||
// fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
|
||||||
// break;
|
|
||||||
//case QtInfoMsg:
|
|
||||||
// fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
|
||||||
// break;
|
|
||||||
//case QtWarningMsg:
|
|
||||||
// fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
|
||||||
// break;
|
|
||||||
//case QtCriticalMsg:
|
|
||||||
// fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
|
||||||
// break;
|
|
||||||
//case QtFatalMsg:
|
|
||||||
// fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
|
||||||
// abort();
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -28,12 +28,9 @@ class MainWindow : public QMainWindow
|
|||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget* aParent = nullptr);
|
explicit MainWindow(QWidget* aParent = nullptr);
|
||||||
~MainWindow() override;
|
~MainWindow() override;
|
||||||
static void QMessageOutput(QtMsgType aType, const QMessageLogContext& aContext, const QString& aMessage);
|
|
||||||
void centerWidgetHide();
|
void centerWidgetHide();
|
||||||
void centerWidgetShow();
|
void centerWidgetShow();
|
||||||
void requestScreenSaver();
|
void requestScreenSaver();
|
||||||
QTextEdit* getEdit();
|
|
||||||
void debugConsoleOn();
|
|
||||||
void grabGestures(const QList<Qt::GestureType>& aGestures);
|
void grabGestures(const QList<Qt::GestureType>& aGestures);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@@ -60,14 +57,14 @@ private:
|
|||||||
private:
|
private:
|
||||||
Ui::MainWindow* mUI;
|
Ui::MainWindow* mUI;
|
||||||
QDockWidget* mDebugConsoleWidget;
|
QDockWidget* mDebugConsoleWidget;
|
||||||
QTextEdit* mDebugMessageConsole;
|
|
||||||
QTabWidget* mTabWidget;
|
QTabWidget* mTabWidget;
|
||||||
InitializeWidget* mInitializWidget;
|
InitializeWidget* mInitializWidget;
|
||||||
ShutdownWidget* mShutdownWidget;
|
ShutdownWidget* mShutdownWidget;
|
||||||
|
|
||||||
int mAdminTabIndex;
|
int mAdminTabIndex;
|
||||||
QThread* mThread;
|
QThread* mThread;
|
||||||
bool mIsDebugMode;
|
bool mTabInited;
|
||||||
|
|
||||||
|
|
||||||
void switchToScanTab(QObject* sender, QObject* data);
|
void switchToScanTab(QObject* sender, QObject* data);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user