Skip to content

Commit 0e2374e

Browse files
authored
Qt6 compatibility (#3779)
1 parent 2ac5797 commit 0e2374e

File tree

8 files changed

+64
-24
lines changed

8 files changed

+64
-24
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ jobs:
233233
include:
234234
- desc: latest releases gcc11 C++17 avx2 exr3.1 ocio2.2
235235
nametag: linux-latest-releases
236-
os: ubuntu-20.04
236+
os: ubuntu-22.04
237237
cc_compiler: gcc-11
238238
cxx_compiler: g++-11
239239
cxx_std: 17
240240
fmt_ver: 9.1.0
241241
openexr_ver: v3.1.5
242242
pybind11_ver: v2.10.0
243-
python_ver: 3.8
243+
python_ver: "3.10"
244244
simd: avx2,f16c
245245
setenvs: export LIBRAW_VERSION=0.20.2
246246
LIBTIFF_VERSION=v4.5.0
@@ -391,6 +391,7 @@ jobs:
391391
cxx_std: 17
392392
python_ver: "3.9"
393393
aclang: 13
394+
setenvs: export QT_VERSION=@5
394395
- desc: MacOS-12
395396
os: macos-12
396397
nametag: macos12-py310

src/build-scripts/gh-installdeps.bash

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ else
7373
libopencolorio-dev \
7474
libopencv-dev \
7575
libhdf5-dev
76-
time sudo apt-get -q install -y \
77-
qt5-default || /bin/true
76+
if [[ "${QT_VERSION:-5}" == "5" ]] ; then
77+
time sudo apt-get -q install -y \
78+
qt5-default || /bin/true
79+
elif [[ "${QT_VERSION}" == "6" ]] ; then
80+
time sudo apt-get -q install -y qt6-base-dev || /bin/true
81+
fi
7882
if [[ "${EXTRA_DEP_PACKAGES}" != "" ]] ; then
7983
time sudo apt-get -q install -y ${EXTRA_DEP_PACKAGES}
8084
fi

src/build-scripts/install_homebrew_deps.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ brew install --display-times -q ffmpeg libheif ptex || true
3939
brew install --display-times -q tbb || true
4040
brew install --display-times -q openvdb || true
4141
brew install --display-times -q opencv || true
42-
brew install --display-times -q qt@5
42+
brew install --display-times -q qt${QT_VERSION}
4343

4444
echo ""
4545
echo "After brew installs:"

src/cmake/externalpackages.cmake

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,21 +255,22 @@ checked_find_package (R3DSDK) # RED camera
255255
set (NUKE_VERSION "7.0" CACHE STRING "Nuke version to target")
256256
checked_find_package (Nuke)
257257

258-
checked_find_package (OpenGL) # used for iv
259258

260259
# Qt -- used for iv
261-
set (qt5_modules Core Gui Widgets)
262-
if (OPENGL_FOUND)
263-
list (APPEND qt5_modules OpenGL)
264-
endif ()
265260
option (USE_QT "Use Qt if found" ON)
266-
checked_find_package (Qt5 COMPONENTS ${qt5_modules})
267-
if (USE_QT AND NOT Qt5_FOUND AND APPLE)
268-
message (STATUS " If you think you installed qt5 with Homebrew and it still doesn't work,")
269-
message (STATUS " try: export PATH=/usr/local/opt/qt5/bin:$PATH")
261+
if (USE_QT)
262+
checked_find_package (OpenGL) # used for iv
263+
endif ()
264+
if (USE_QT AND OPENGL_FOUND)
265+
checked_find_package (Qt6 COMPONENTS Core Gui Widgets OpenGLWidgets)
266+
if (NOT Qt6_FOUND)
267+
checked_find_package (Qt5 COMPONENTS Core Gui Widgets OpenGL)
268+
endif ()
269+
if (NOT Qt5_FOUND AND NOT Qt6_FOUND AND APPLE)
270+
message (STATUS " If you think you installed qt with Homebrew and it still doesn't work,")
271+
message (STATUS " try: export PATH=/usr/local/opt/qt/bin:$PATH")
272+
endif ()
270273
endif ()
271-
272-
273274

274275

275276
###########################################################################

src/iv/CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,36 @@
33
# https://github.com/OpenImageIO/oiio
44

55
set (CMAKE_AUTOMOC ON)
6-
if (Qt5_POSITION_INDEPENDENT_CODE)
6+
if (Qt5_POSITION_INDEPENDENT_CODE OR Qt6_POSITION_INDEPENDENT_CODE)
77
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
88
endif()
99

1010
check_is_enabled (iv iv_enabled)
11-
if (iv_enabled AND Qt5_FOUND AND OPENGL_FOUND)
11+
if (iv_enabled AND (Qt5_FOUND OR Qt6_FOUND) AND OPENGL_FOUND)
1212
fancy_add_executable (
1313
SYSTEM_INCLUDE_DIRS
1414
${OPENGL_INCLUDE_DIR}
1515
LINK_LIBRARIES
1616
OpenImageIO
17-
Qt5::Core Qt5::Gui Qt5::Widgets Qt5::OpenGL
17+
$<TARGET_NAME_IF_EXISTS:Qt5::Core>
18+
$<TARGET_NAME_IF_EXISTS:Qt5::Gui>
19+
$<TARGET_NAME_IF_EXISTS:Qt5::Widgets>
20+
$<TARGET_NAME_IF_EXISTS:Qt5::OpenGL>
21+
$<TARGET_NAME_IF_EXISTS:Qt6::Core>
22+
$<TARGET_NAME_IF_EXISTS:Qt6::Gui>
23+
$<TARGET_NAME_IF_EXISTS:Qt6::Widgets>
24+
$<TARGET_NAME_IF_EXISTS:Qt6::OpenGLWidgets>
1825
${OPENGL_LIBRARIES}
1926
)
2027
if (iv_enabled AND FORCE_OPENGL_1)
2128
target_compile_definitions(iv PRIVATE FORCE_OPENGL_1)
2229
endif()
30+
if (Qt5_FOUND)
31+
target_compile_definitions(iv PRIVATE OIIO_QT_MAJOR=5)
32+
endif ()
33+
if (Qt6_FOUND)
34+
target_compile_definitions(iv PRIVATE OIIO_QT_MAJOR=6)
35+
endif ()
2336
else ()
2437
message (STATUS "\n\n WARNING: Qt or OpenGL not found -- 'iv' will not be built!\n")
2538
endif ()

src/iv/imageviewer.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
#endif
1010
#include <vector>
1111

12+
#ifndef OIIO_QT_MAJOR
13+
# error "Build problem? OIIO_QT_MAJOR not defined."
14+
#endif
15+
1216
#include "imageviewer.h"
1317
#include "ivgl.h"
1418

1519
#include <QApplication>
1620
#include <QComboBox>
17-
#include <QDesktopWidget>
1821
#include <QFileDialog>
1922
#include <QKeyEvent>
2023
#include <QLabel>
@@ -28,6 +31,10 @@
2831
#include <QStatusBar>
2932
#include <QTimer>
3033

34+
#if OIIO_QT_MAJOR < 6
35+
# include <QDesktopWidget>
36+
#endif
37+
3138
#include <OpenImageIO/dassert.h>
3239
#include <OpenImageIO/filesystem.h>
3340
#include <OpenImageIO/imagecache.h>
@@ -1951,9 +1958,14 @@ ImageViewer::fitWindowToImage(bool zoomok, bool minsize)
19511958
}
19521959

19531960
if (!m_fullscreen) {
1954-
QDesktopWidget* desktop = QApplication::desktop();
1955-
QRect availgeom = desktop->availableGeometry(this);
1956-
int availwidth = availgeom.width() - extraw - 20;
1961+
#if OIIO_QT_MAJOR >= 6
1962+
auto desktop = this->screen();
1963+
QRect availgeom = desktop->availableGeometry();
1964+
#else
1965+
auto desktop = QApplication::desktop();
1966+
QRect availgeom = desktop->availableGeometry(this);
1967+
#endif
1968+
int availwidth = availgeom.width() - extraw - 20;
19571969
int availheight = availgeom.height() - extrah - menuBar()->height()
19581970
- 20;
19591971
#if 0

src/iv/imageviewer.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
#include <QAction>
2424
#include <QCheckBox>
2525
#include <QDialog>
26-
#include <QGLWidget>
2726
#include <QMainWindow>
2827

28+
#if OIIO_QT_MAJOR < 6
29+
# include <QGLWidget>
30+
#else
31+
# include <QOpenGLWidget>
32+
#endif
33+
2934
#ifndef QT_NO_PRINTER
3035
// #include <QPrinter>
3136
#endif

src/iv/ivgl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include <QLabel>
1212
#include <QMouseEvent>
1313
#include <QProgressBar>
14+
#if OIIO_QT_MAJOR >= 6
15+
# include <QPainter>
16+
# include <QPen>
17+
#endif
1418

1519
#include "ivutils.h"
1620
#include <OpenImageIO/strutil.h>

0 commit comments

Comments
 (0)