forked from openkylin/ukui-search
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:
|
||||
~AppInfoTablePrivate();
|
||||
void initDateBaseConnection();
|
||||
void openDataBase();
|
||||
bool initDateBaseConnection();
|
||||
bool openDataBase();
|
||||
void closeDataBase();
|
||||
|
||||
AppInfoTable *q = nullptr;
|
||||
|
|
|
@ -25,7 +25,10 @@ AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent)
|
|||
break;
|
||||
}
|
||||
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)
|
||||
|
@ -653,24 +656,26 @@ AppInfoTablePrivate::~AppInfoTablePrivate()
|
|||
this->closeDataBase();
|
||||
}
|
||||
|
||||
void AppInfoTablePrivate::initDateBaseConnection()
|
||||
bool AppInfoTablePrivate::initDateBaseConnection()
|
||||
{
|
||||
m_database->setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME);
|
||||
if(!m_database->open()) {
|
||||
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->setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME);
|
||||
|
||||
if(!m_database->open()) {
|
||||
qWarning() << m_database->lastError();
|
||||
QApplication::quit();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AppInfoTablePrivate::closeDataBase()
|
||||
|
|
|
@ -76,6 +76,8 @@ private:
|
|||
bool updateAppLaunchTimes(QString &desktopfp);
|
||||
|
||||
AppInfoTablePrivate *d;
|
||||
Q_SIGNALS:
|
||||
void DBOpenFailed();
|
||||
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue