Skip to content

Commit

Permalink
Fix issues preventing library from building with Qt 6
Browse files Browse the repository at this point in the history
1. CMake instructions now handle both Qt 6 and Qt 5
2. Pass correct QString-like type to setWindowTitle
3. Remove qAsConst optimization to address deprecation warning
  • Loading branch information
Cuperino committed Jun 10, 2024
1 parent b59d58f commit 73b2bfa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
32 changes: 32 additions & 0 deletions cmake/Qt6Portability.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

include_directories(${QtWidgets_INCLUDE_DIRS})

if(QT_USE_QTNETWORK)
find_package(QtNetwork REQUIRED)
list(APPEND QT_LIBRARIES Qt::Network)
include_directories(${QtNetwork_INCLUDE_DIRS})
endif()

if(QT_USE_QTXML)
find_package(QtXml REQUIRED)
list(APPEND QT_LIBRARIES Qt::Xml)
include_directories(${QtXml_INCLUDE_DIRS})
endif()

if(QT_USE_QTTEST)
find_package(QtTest REQUIRED)
list(APPEND QT_LIBRARIES Qt::Test)
include_directories(${QtTest_INCLUDE_DIRS})
endif()

macro(qt4_wrap_ui)
qt_wrap_ui(${ARGN})
endmacro()

macro(qt4_wrap_cpp)
qt_wrap_cpp(${ARGN})
endmacro()

macro(qt4_add_resources)
qt_add_resources(${ARGN})
endmacro()
4 changes: 2 additions & 2 deletions examples/mactouchbar/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected].
** Copyright (C) 2024 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected].
** All rights reserved.
**
** This file is part of the KD MacTouchBar library.
Expand Down Expand Up @@ -34,7 +34,7 @@

MainWindow::MainWindow()
{
setWindowTitle("KDMacTouchBar Example");
setWindowTitle(tr("KDMacTouchBar Example"));
resize(400, 200);

// attach a touchbar to this window
Expand Down
4 changes: 2 additions & 2 deletions src/kdmactouchbar.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected].
** Copyright (C) 2024 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected].
** All rights reserved.
**
** This file is part of the KD MacTouchBar library.
Expand Down Expand Up @@ -49,7 +49,7 @@

auto nsImage = [[[NSImage alloc] initWithSize:NSZeroSize] autorelease];

for (const auto& size : qAsConst(sizes)) {
for (const auto& size : sizes) {
const QImage qimage = icon.pixmap(size).toImage();
CGImageRef cgImage = qimage.toCGImage();
if (!cgImage)
Expand Down

0 comments on commit 73b2bfa

Please sign in to comment.