From 0fc071d22842044591ceb48ecc56cafe4d8d5dce Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Tue, 27 Feb 2024 13:14:24 -0500 Subject: [PATCH] chat: better handle case where network reachability is unknown Signed-off-by: Jared Van Bortel --- gpt4all-chat/llm.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gpt4all-chat/llm.cpp b/gpt4all-chat/llm.cpp index 0f454908..f9cb698b 100644 --- a/gpt4all-chat/llm.cpp +++ b/gpt4all-chat/llm.cpp @@ -42,8 +42,11 @@ LLM::LLM() m_compatHardware = minimal; QNetworkInformation::loadDefaultBackend(); - connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, - this, &LLM::isNetworkOnlineChanged); + auto * netinfo = QNetworkInformation::instance(); + if (netinfo) { + connect(netinfo, &QNetworkInformation::reachabilityChanged, + this, &LLM::isNetworkOnlineChanged); + } } bool LLM::hasSettingsAccess() const @@ -108,8 +111,6 @@ QString LLM::systemTotalRAMInGBString() const bool LLM::isNetworkOnline() const { - if (!QNetworkInformation::instance()) - return false; - - return QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online; + auto * netinfo = QNetworkInformation::instance(); + return !netinfo || netinfo->reachability() == QNetworkInformation::Reachability::Online; }