Fix: The AppDatabase exception will cause the program that calls it to exit.
This commit is contained in:
parent
7b957b6cc7
commit
57df997039
|
@ -45,8 +45,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~AppInfoTablePrivate();
|
~AppInfoTablePrivate();
|
||||||
void initDateBaseConnection();
|
bool initDateBaseConnection();
|
||||||
void openDataBase();
|
bool openDataBase();
|
||||||
void closeDataBase();
|
void closeDataBase();
|
||||||
|
|
||||||
AppInfoTable *q = nullptr;
|
AppInfoTable *q = nullptr;
|
||||||
|
|
|
@ -25,7 +25,10 @@ AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
qDebug() << "App info database currunt connection name:" << m_ConnectionName;
|
qDebug() << "App info database currunt connection name:" << m_ConnectionName;
|
||||||
this->openDataBase();
|
if (!this->openDataBase()) {
|
||||||
|
Q_EMIT q->DBOpenFailed();
|
||||||
|
qWarning() << "Fail to open App DataBase, because:" << m_database->lastError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppInfoTablePrivate::setAppFavoritesState(QString &desktopfp, size_t num)
|
bool AppInfoTablePrivate::setAppFavoritesState(QString &desktopfp, size_t num)
|
||||||
|
@ -653,24 +656,26 @@ AppInfoTablePrivate::~AppInfoTablePrivate()
|
||||||
this->closeDataBase();
|
this->closeDataBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppInfoTablePrivate::initDateBaseConnection()
|
bool AppInfoTablePrivate::initDateBaseConnection()
|
||||||
{
|
{
|
||||||
m_database->setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME);
|
m_database->setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME);
|
||||||
if(!m_database->open()) {
|
if(!m_database->open()) {
|
||||||
qWarning() << m_database->lastError();
|
qWarning() << m_database->lastError();
|
||||||
QApplication::quit();
|
return false;
|
||||||
|
// QApplication::quit();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppInfoTablePrivate::openDataBase()
|
bool AppInfoTablePrivate::openDataBase()
|
||||||
{
|
{
|
||||||
*m_database = QSqlDatabase::addDatabase("QSQLITE", m_ConnectionName);
|
*m_database = QSqlDatabase::addDatabase("QSQLITE", m_ConnectionName);
|
||||||
m_database->setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME);
|
m_database->setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME);
|
||||||
|
|
||||||
if(!m_database->open()) {
|
if(!m_database->open()) {
|
||||||
qWarning() << m_database->lastError();
|
return false;
|
||||||
QApplication::quit();
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppInfoTablePrivate::closeDataBase()
|
void AppInfoTablePrivate::closeDataBase()
|
||||||
|
|
|
@ -76,6 +76,8 @@ private:
|
||||||
bool updateAppLaunchTimes(QString &desktopfp);
|
bool updateAppLaunchTimes(QString &desktopfp);
|
||||||
|
|
||||||
AppInfoTablePrivate *d;
|
AppInfoTablePrivate *d;
|
||||||
|
Q_SIGNALS:
|
||||||
|
void DBOpenFailed();
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue