From 09059ab869222579acb6c47a3f166f13e344b00f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 29 Dec 2023 22:04:24 -0500 Subject: [PATCH] Apply de minimis adaptations to get to build under Qt6. --- OSBindings/Qt/clksignal.pro | 8 ++++---- OSBindings/Qt/mainwindow.cpp | 21 ++++++++++++--------- OSBindings/Qt/mainwindow.h | 5 ++--- OSBindings/Qt/scantargetwidget.cpp | 6 +----- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/OSBindings/Qt/clksignal.pro b/OSBindings/Qt/clksignal.pro index f121d8636..3353d979e 100644 --- a/OSBindings/Qt/clksignal.pro +++ b/OSBindings/Qt/clksignal.pro @@ -1,4 +1,4 @@ -QT += core gui multimedia widgets +QT += core gui multimedia widgets openglwidgets # Be specific about C++17 but also try the vaguer C++1z for older # versions of Qt. @@ -24,10 +24,10 @@ DEFINES += TARGET_QT DEFINES += IGNORE_APPLE QMAKE_CXXFLAGS_RELEASE += -DNDEBUG -# Generate warnings for any use of APIs deprecated prior to Qt 6.0.0. -# Development was performed against Qt 5.14. +# Generate warnings for any use of APIs deprecated prior to Qt 7.0.0. +# Development was performed against Qt 6.6.1. DEFINES += QT_DEPRECATED_WARNINGS -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x070000 SRC = $$PWD/../.. diff --git a/OSBindings/Qt/mainwindow.cpp b/OSBindings/Qt/mainwindow.cpp index 1e36e338c..900d29089 100644 --- a/OSBindings/Qt/mainwindow.cpp +++ b/OSBindings/Qt/mainwindow.cpp @@ -5,6 +5,9 @@ #include #include +#include +#include + #include #include @@ -314,24 +317,24 @@ void MainWindow::launchMachine() { static constexpr size_t samplesPerBuffer = 256; // TODO: select this dynamically. const auto speaker = audio_producer->get_speaker(); if(speaker) { - const QAudioDeviceInfo &defaultDeviceInfo = QAudioDeviceInfo::defaultOutputDevice(); - if(!defaultDeviceInfo.isNull()) { - QAudioFormat idealFormat = defaultDeviceInfo.preferredFormat(); + QAudioDevice device(QMediaDevices::defaultAudioOutput()); + if(true) { // TODO: how to check that audio output is available in Qt6? + QAudioFormat idealFormat = device.preferredFormat(); // Use the ideal format's sample rate, provide stereo as long as at least two channels // are available, and — at least for now — assume a good buffer size. audioIsStereo = (idealFormat.channelCount() > 1) && speaker->get_is_stereo(); - audioIs8bit = idealFormat.sampleSize() < 16; + audioIs8bit = idealFormat.sampleFormat() == QAudioFormat::UInt8; idealFormat.setChannelCount(1 + int(audioIsStereo)); - idealFormat.setSampleSize(audioIs8bit ? 8 : 16); + idealFormat.setSampleFormat(audioIs8bit ? QAudioFormat::UInt8 : QAudioFormat::Int16); speaker->set_output_rate(idealFormat.sampleRate(), samplesPerBuffer, audioIsStereo); speaker->set_delegate(this); audioThread.start(); - audioThread.performAsync([this, idealFormat] { + audioThread.performAsync([&] { // Create an audio output. - audioOutput = std::make_unique(idealFormat); + audioOutput = std::make_unique(device, idealFormat); // Start the output. The additional `audioBuffer` is meant to minimise latency, // believe it or not, given Qt's semantics. @@ -373,13 +376,13 @@ void MainWindow::launchMachine() { QAction *const asKeyboardAction = new QAction(tr("Use Keyboard as Keyboard"), this); asKeyboardAction->setCheckable(true); asKeyboardAction->setChecked(true); - asKeyboardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K)); + // asKeyboardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K)); inputMenu->addAction(asKeyboardAction); QAction *const asJoystickAction = new QAction(tr("Use Keyboard as Joystick"), this); asJoystickAction->setCheckable(true); asJoystickAction->setChecked(false); - asJoystickAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J)); + // asJoystickAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J)); inputMenu->addAction(asJoystickAction); connect(asKeyboardAction, &QAction::triggered, this, [=] { diff --git a/OSBindings/Qt/mainwindow.h b/OSBindings/Qt/mainwindow.h index e2f434290..e60f17a97 100644 --- a/OSBindings/Qt/mainwindow.h +++ b/OSBindings/Qt/mainwindow.h @@ -1,12 +1,11 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +#include #include #include #include -#include #include "audiobuffer.h" #include "timer.h" @@ -71,7 +70,7 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat std::unique_ptr machine; std::mutex machineMutex; - std::unique_ptr audioOutput; + std::unique_ptr audioOutput; bool audioIs8bit = false, audioIsStereo = false; void speaker_did_complete_samples(Outputs::Speaker::Speaker *speaker, const std::vector &buffer) override; AudioBuffer audioBuffer; diff --git a/OSBindings/Qt/scantargetwidget.cpp b/OSBindings/Qt/scantargetwidget.cpp index bdb71e62b..93d100e13 100644 --- a/OSBindings/Qt/scantargetwidget.cpp +++ b/OSBindings/Qt/scantargetwidget.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -30,10 +29,7 @@ void ScanTargetWidget::paintGL() { requestedRedrawTime = 0; } - // TODO: if Qt 5.14 can be guaranteed, just use window()->screen(). - const auto screenNumber = QApplication::desktop()->screenNumber(this); - QScreen *const screen = QGuiApplication::screens()[screenNumber]; - + QScreen *const screen = window()->screen(); const float newOutputScale = float(screen->devicePixelRatio()); if(outputScale != newOutputScale) { outputScale = newOutputScale;