Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with Qt 6.8 #3121

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gpt4all-chat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

### Changed
- Implement Qt 6.8 compatibility ([#3121](https://github.com/nomic-ai/gpt4all/pull/3121))

## [3.4.2] - 2024-10-16

### Fixed
Expand Down Expand Up @@ -164,6 +169,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Fix several Vulkan resource management issues ([#2694](https://github.com/nomic-ai/gpt4all/pull/2694))
- Fix crash/hang when some models stop generating, by showing special tokens ([#2701](https://github.com/nomic-ai/gpt4all/pull/2701))

[Unreleased]: https://github.com/nomic-ai/gpt4all/compare/v3.4.2...HEAD
[3.4.2]: https://github.com/nomic-ai/gpt4all/compare/v3.4.1...v3.4.2
[3.4.1]: https://github.com/nomic-ai/gpt4all/compare/v3.4.0...v3.4.1
[3.4.0]: https://github.com/nomic-ai/gpt4all/compare/v3.3.0...v3.4.0
Expand Down
4 changes: 4 additions & 0 deletions gpt4all-chat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ configure_file(

find_package(Qt6 6.4 COMPONENTS Core HttpServer LinguistTools Pdf Quick QuickDialogs2 Sql Svg REQUIRED)

if (QT_KNOWN_POLICY_QTP0004)
qt_policy(SET QTP0004 NEW) # generate extra qmldir files on Qt 6.8+
endif()

# Get the Qt6Core target properties
get_target_property(Qt6Core_INCLUDE_DIRS Qt6::Core INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(Qt6Core_LIBRARY_RELEASE Qt6::Core LOCATION_RELEASE)
Expand Down
1 change: 1 addition & 0 deletions gpt4all-chat/qml/MySettingsStack.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import QtCore
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtQuick.Controls.impl
manyoso marked this conversation as resolved.
Show resolved Hide resolved
import QtQuick.Layouts
import QtQuick.Dialogs
import Qt.labs.folderlistmodel
Expand Down
33 changes: 29 additions & 4 deletions gpt4all-chat/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include <unordered_map>
#include <utility>

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
# include <QTcpServer>
#endif

using namespace std::string_literals;
using namespace Qt::Literals::StringLiterals;

Expand Down Expand Up @@ -435,7 +439,6 @@ T &parseRequest(T &request, QJsonObject &&obj)
Server::Server(Chat *chat)
: ChatLLM(chat, true /*isServer*/)
, m_chat(chat)
, m_server(nullptr)
{
connect(this, &Server::threadStarted, this, &Server::start);
connect(this, &Server::databaseResultsChanged, this, &Server::handleDatabaseResultsChanged);
Expand All @@ -457,10 +460,23 @@ static QJsonObject requestFromJson(const QByteArray &request)
void Server::start()
{
m_server = std::make_unique<QHttpServer>(this);
if (!m_server->listen(QHostAddress::LocalHost, MySettings::globalInstance()->networkPort())) {
qWarning() << "ERROR: Unable to start the server";
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
auto *tcpServer = new QTcpServer(m_server.get());
#else
auto *tcpServer = m_server.get();
#endif

auto port = MySettings::globalInstance()->networkPort();
if (!tcpServer->listen(QHostAddress::LocalHost, port)) {
qWarning() << "Server ERROR: Failed to listen on port" << port;
return;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
if (!m_server->bind(tcpServer)) {
qWarning() << "Server ERROR: Failed to HTTP server to socket" << port;
return;
}
#endif

m_server->route("/v1/models", QHttpServerRequest::Method::Get,
[](const QHttpServerRequest &) {
Expand Down Expand Up @@ -600,10 +616,19 @@ void Server::start()
}
);

m_server->afterRequest([] (QHttpServerResponse &&resp) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
m_server->addAfterRequestHandler(this, [](const QHttpServerRequest &req, QHttpServerResponse &resp) {
Q_UNUSED(req);
auto headers = resp.headers();
headers.append("Access-Control-Allow-Origin"_L1, "*"_L1);
resp.setHeaders(std::move(headers));
});
#else
m_server->afterRequest([](QHttpServerResponse &&resp) {
resp.addHeader("Access-Control-Allow-Origin", "*");
return std::move(resp);
});
#endif

connect(this, &Server::requestServerNewPromptResponsePair, m_chat,
&Chat::serverNewPromptResponsePair, Qt::BlockingQueuedConnection);
Expand Down