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(LastOperation)\
|
||||
ADD_APP_VALUE(EmptyScanFlag)\
|
||||
ADD_APP_VALUE(DBconnected)\
|
||||
|
||||
|
||||
#include <QApplication>
|
||||
#include <QVariant>
|
||||
|
||||
@@ -21,7 +21,12 @@ bool SQLHelper::Open() {
|
||||
defaultDatabase->setDatabaseName("USCT"); // 数据库名称
|
||||
defaultDatabase->setUserName("rc"); // 数据库用户名
|
||||
defaultDatabase->setPassword("123$%^"); // 数据库密码
|
||||
return defaultDatabase->open();
|
||||
bool ret = defaultDatabase->open();
|
||||
if (!ret){
|
||||
delete defaultDatabase;
|
||||
defaultDatabase = nullptr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SQLHelper::Open(QSqlDatabase *base) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#define ADD_EVENT()\
|
||||
ADD_EVENT_VALUE(RequestLogin)\
|
||||
ADD_EVENT_VALUE(LoginSuccess)\
|
||||
ADD_EVENT_VALUE(RequestShutdown)\
|
||||
ADD_EVENT_VALUE(LoginRoleChanged)\
|
||||
ADD_EVENT_VALUE(PatientSelected)\
|
||||
|
||||
43
src/main.cpp
43
src/main.cpp
@@ -18,6 +18,7 @@
|
||||
#include "src/utilities/LanguageSwitcher.h"
|
||||
#include "utilities/TouchScreenSignalSender.h"
|
||||
#include "keyboard/KeyboardManager.h"
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
|
||||
QString loadFontFromFile(QString path)
|
||||
{
|
||||
@@ -74,14 +75,7 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
a.setStyleSheet(QLatin1String(file.readAll()));
|
||||
}
|
||||
|
||||
|
||||
bool sqlConnected= SQLHelper::Open();
|
||||
if (!sqlConnected)
|
||||
{
|
||||
//TODO: 数据库连接失败错误
|
||||
exit(-99);
|
||||
}
|
||||
AppGlobalValues::setDBconnected(false);
|
||||
MainWindow w;
|
||||
DialogManager::Default()->init(&w);
|
||||
UserOperationLog::Default()->init();
|
||||
@@ -98,37 +92,10 @@ int main(int argc, char* argv[])
|
||||
KeyboardManager::getInstance();
|
||||
UserOperationLog::cleanHistoryLog();
|
||||
|
||||
if (app_args.contains("-d"))
|
||||
//if (true)
|
||||
{
|
||||
w.showFullScreen();
|
||||
DeviceManager::Default()->initDevice();
|
||||
|
||||
w.debugConsoleOn();
|
||||
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();
|
||||
}
|
||||
ret = a.exec();
|
||||
DeviceManager::Default()->close();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#include "log/UserOperationLog.h"
|
||||
#include "json/jsonobject.h"
|
||||
#include "components/ULineEdit.h"
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include "db/SQLHelper.h"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -158,6 +161,18 @@ void LoginDialog::clearInputData()
|
||||
|
||||
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)
|
||||
{
|
||||
mErrorMessage->setText(QString(tr("Login locked. Please retry after %1 minutes.")).arg(LOGIN_LOCK_MINUTIES));
|
||||
@@ -176,6 +191,7 @@ void LoginDialog::doLogin()
|
||||
{
|
||||
resetLoginFailedCount();
|
||||
mErrorMessage->setVisible(false);
|
||||
EventCenter::Default()->triggerEvent(GUIEvents::LoginSuccess,nullptr,nullptr);
|
||||
accept();
|
||||
LOG_USER_OPERATION("Login Sucessful");
|
||||
JsonObject::Instance()->setDefaultUser(strUserCode);
|
||||
|
||||
@@ -31,18 +31,17 @@ MainWindow::MainWindow(QWidget* aParent)
|
||||
: QMainWindow(aParent)
|
||||
, mUI(new Ui::MainWindow)
|
||||
, mDebugConsoleWidget(nullptr)
|
||||
, mDebugMessageConsole(nullptr)
|
||||
, mTabWidget(new QTabWidget(this))
|
||||
, mInitializWidget(new InitializeWidget(this))
|
||||
, mShutdownWidget(new ShutdownWidget(nullptr))
|
||||
, mAdminTabIndex(-1)
|
||||
, mThread(nullptr)
|
||||
, mIsDebugMode(false)
|
||||
, mTabInited(false)
|
||||
{
|
||||
mUI->setupUi(this);
|
||||
this->setWindowFlags(Qt::Window);
|
||||
|
||||
initializeTabWidget();
|
||||
|
||||
initializeLayout();
|
||||
|
||||
connect(EventCenter::Default(), &EventCenter::PatientSelected, this,&MainWindow::switchToScanTab);
|
||||
@@ -59,8 +58,18 @@ MainWindow::MainWindow(QWidget* aParent)
|
||||
connect(DialogManager::Default(), &DialogManager::loginDialogShown, this, [this]()
|
||||
{
|
||||
mInitializWidget->setVisible(false);
|
||||
|
||||
});
|
||||
connect(EventCenter::Default(), &EventCenter::LoginSuccess, this, [this]()
|
||||
{
|
||||
if(!mTabInited){
|
||||
mTabInited = true;
|
||||
initializeTabWidget();
|
||||
mTabWidget->setCurrentIndex(0);
|
||||
}
|
||||
mTabWidget->setVisible(true);
|
||||
});
|
||||
|
||||
GUIErrorHandle::Default()->init();
|
||||
QApplication::setActiveWindow(centralWidget());
|
||||
}
|
||||
@@ -105,13 +114,14 @@ void MainWindow::initializeTabWidget()
|
||||
{
|
||||
mTabWidget->setTabPosition(QTabWidget::South);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -251,36 +261,6 @@ void MainWindow::swipeTriggered(QSwipeGesture* aSwipeGesture)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
//------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:
|
||||
explicit MainWindow(QWidget* aParent = nullptr);
|
||||
~MainWindow() override;
|
||||
static void QMessageOutput(QtMsgType aType, const QMessageLogContext& aContext, const QString& aMessage);
|
||||
void centerWidgetHide();
|
||||
void centerWidgetShow();
|
||||
void requestScreenSaver();
|
||||
QTextEdit* getEdit();
|
||||
void debugConsoleOn();
|
||||
void grabGestures(const QList<Qt::GestureType>& aGestures);
|
||||
|
||||
public slots:
|
||||
@@ -60,14 +57,14 @@ private:
|
||||
private:
|
||||
Ui::MainWindow* mUI;
|
||||
QDockWidget* mDebugConsoleWidget;
|
||||
QTextEdit* mDebugMessageConsole;
|
||||
QTabWidget* mTabWidget;
|
||||
InitializeWidget* mInitializWidget;
|
||||
ShutdownWidget* mShutdownWidget;
|
||||
|
||||
int mAdminTabIndex;
|
||||
QThread* mThread;
|
||||
bool mIsDebugMode;
|
||||
bool mTabInited;
|
||||
|
||||
|
||||
void switchToScanTab(QObject* sender, QObject* data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user