Issue: Mac OS: other widget cannot show when use SDL_CreateWindowFrom() to bind a widget
-
wrote on 10 Dec 2024, 11:34 last edited by
hi all:
I am using QT 5.15.16 + SDL 2.30.10 for testing, right now I create 2 widgets, one widget call video widget use to display YUV data, other widget call control widget which has some PushButtons.
on the video widget, use SDL_CreateWindowFrom() to bind this widget, and want to show YUV data via SDL_RenderCopy/SDL_RenderPresent API.
when render it on macOS, the control widget desn't work, it just show black. what is problem? is it the known issue on QT?
this code can work fine on Windows + Ubuntu.here is the code:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <thread> #include <QTimer> #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); SDL_Init(SDL_INIT_VIDEO); window = nullptr; render = nullptr; window= SDL_CreateWindowFrom((void *)ui->video->winId()); render = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &MainWindow::renderYUV); timer->start(1000 / 30); } void MainWindow::renderYUV() { SDL_Rect rect = {}; width = ui->video->width(); height = ui->video->height(); qDebug() << "w :" << width << " h:" << height; yPlane = new uint8_t[width * height]; // Y plane uPlane = new uint8_t[width * height / 4]; // U plane vPlane = new uint8_t[width * height / 4]; // V plane // fill YUV data for (int i = 0; i < width * height; ++i) { yPlane[i] = 128; // Y } for (int i = 0; i < width * height / 4; ++i) { uPlane[i] = 128; // U vPlane[i] = 128; // V } SDL_Texture *texture = SDL_CreateTexture(render, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, width, height); if (!texture) { qDebug() << "Failed to create texture: " << SDL_GetError(); return; } SDL_UpdateTexture(texture, nullptr, yPlane, width); SDL_RenderClear(render); rect.x = 0; rect.y = 0; rect.w = ui->video->width(); rect.h = ui->video->height(); qDebug() << "display rect x " << rect.x << " y " << rect.y << " w " << rect.w << " h " << rect.h; SDL_RenderCopy(render, texture, nullptr, &rect); SDL_RenderPresent(render); SDL_DestroyTexture(texture); } MainWindow::~MainWindow() { delete ui; }
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> extern "C" { #include <SDL.h> #include <SDL_audio.h> #include <SDL_types.h> #include <SDL_name.h> #include <SDL_main.h> #include <SDL_config.h> } QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); SDL_Window *window; SDL_Renderer *render; uint8_t *yPlane, *uPlane, *vPlane; int width, height; private slots: void renderYUV(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
-
Hi and welcome to devnet,
Which version of macOS ?
How did you install that version of Qt ?
How did you install SDL ?
Do you have any message on the terminal when your application runs ? -
wrote on 10 Dec 2024, 23:35 last edited by
the version os Macos : 15.1.1 on M2 CPU
the QT version is 5.15.16, I built the QT from source code. like below command:
./configure -prefix /Users/figo/opt/qt5.15 -opensource -confirm-license -nomake examples -nomake tests -skip purchasing -skip serialbus -skip qtserialport -skip speech -qt-libpng -qt-libjpeg -qt-zlib -qt-pcre -no-freetype -qt-harfbuzz -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwebchannel QMAKE_APPLE_DEVICE_ARCHS="arm64" -skip qtlocationThe SDL version is 2.30.10, installed by this command: brew install SDL2.
here is the log, but I cannot see any error log:
07:34:05: Starting /Users/figo/work/tmp/test_qt_sdl/test/build/Desktop_arm_darwin_generic_mach_o_64bit-Debug/test.app/Contents/MacOS/test...
2024-12-11 07:34:05.949 test[73738:9209395] INFO: Created renderer: metal
2024-12-11 07:34:06.035 test[73738:9209395] +[IMKClient subclass]: chose IMKClient_Modern
2024-12-11 07:34:06.035 test[73738:9209395] +[IMKInputSession subclass]: chose IMKInputSession_Modern -
wrote on 10 Dec 2024, 23:48 last edited by
I add this line in the code:
QLoggingCategory::setFilterRules("*.debug=true");Here is the log:
qt.qpa.window: QCocoaWindow::QCocoaWindow QWidgetWindow(0x60000017e6a0, name="MainWindowWindow")
qt.qpa.window: QCocoaWindow::initialize QWidgetWindow(0x60000017e6a0, name="MainWindowWindow")
qt.qpa.drawing: Making <QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))> layer-backed with <NSViewBackingLayer: 0x600002b49c50> due to being enabled by macOS
qt.qpa.window: QCocoaWindow::setGeometry QWidgetWindow(0x60000017e6a0, name="MainWindowWindow") QRect(584,246 751x540)
qt.qpa.window: QCocoaWindow::setCocoaGeometry QWidgetWindow(0x60000017e6a0, name="MainWindowWindow") QRect(584,246 751x540)
qt.qpa.cocoa.notifications: Forwarding NSViewFrameDidChangeNotification to QVector(QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow")))
qt.qpa.window: QCocoaWindow::recreateWindowIfNeeded QWidgetWindow(0x60000017e6a0, name="MainWindowWindow") QFlagsQCocoaWindow::RecreationReason(MissingWindow|ContentViewChanged)
qt.qpa.window: Ensuring that <QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))> is content view for <QNSWindow: 0x12206a0c0; contentView=NSObject(0x0)>
qt.qpa.window: Re-parenting <QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))> from NSObject(0x0) to <NSThemeFrame: 0x120e32cd0>
qt.qpa.window: Done re-parenting <QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))> into <NSThemeFrame: 0x120e32cd0>
qt.qpa.window: Moving <QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))> from NSObject(0x0) to <QNSWindow: 0x12206a0c0; contentView=<QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))>>
qt.qpa.window: Done moving <QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))> to <QNSWindow: 0x12206a0c0; contentView=<QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))>>
qt.qpa.drawing: Backing properties changed for <QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))>
qt.qpa.drawing: Updating <NSViewBackingLayer: 0x600002b49c50> content scale to 1
qt.qpa.cocoa.notifications: Forwarding NSViewFrameDidChangeNotification to QVector(QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow")))
qt.qpa.window: QCocoaWindow::propagateSizeHints QWidgetWindow(0x60000017e6a0, name="MainWindowWindow") min: QSize(0, 0) max: QSize(16777215, 16777215) increment: QSize(-1, -1) base: QSize(-1, -1)
qt.qpa.window: QCocoaWindow::setMask QWidgetWindow(0x60000017e6a0, name="MainWindowWindow") QRegion(null)
qt.qpa.backingstore: Creating QCALayerBackingStore for QWidgetWindow(0x60000017e6a0, name="MainWindowWindow")
qt.qpa.fonts: Populating font database...
qt.qpa.fonts: Populating available families took 13 ms
qt.qpa.fonts: Resolving theme fonts took 0 ms
qt.text.font.db: Adding font: familyName ".AppleSystemUIFont" stylename "Regular" weight 50 style QFont::StyleNormal pixelSize 0 antialiased true fixed false
qt.text.font.db: Adding font: familyName ".AppleSystemUIFont" stylename "Regular" weight 50 style QFont::StyleNormal pixelSize 0 antialiased true fixed false
qt.qpa.fonts: Populating system descriptors took 23 ms
qt.text.font.match: QFontDatabase::match
request:
family: .AppleSystemUIFont [-- any --], script: 2
weight: 50, style: 0
stretch: 0
pixelSize: 13
pitch: *
qt.text.font.match: REMARK: looking for best foundry for family '.AppleSystemUIFont' [1]
qt.text.font.match: looking for matching style in foundry 'CoreText' 2
qt.text.font.match: best style has distance 0x0
qt.text.font.match: found smoothly scalable font (13 pixels)
qt.text.font.match: found a match: score 0 best score so far ffffffff
qt.qpa.fonts: Resolved font smoothing algorithm. Defaults = {
AppleFontSmoothing = "<null>";
CGFontRenderingFontSmoothingDisabled = "<null>";
} Result = QCoreTextFontEngine::Grayscale
qt.accessibility.cache: insert - id: 2147483648 iface: QAccessibleInterface(0x60000254c180 name="PushButton" role=Button obj=QPushButton(0x600002b4f9c0, name = "pushButton")"focusable|invisible")
qt.accessibility.cache: insert - id: 2147483649 iface: QAccessibleInterface(0x60000254fec0 name="PushButton" role=Button obj=QPushButton(0x600002b4fab0, name = "pushButton_2")"focusable|invisible")
qt.qpa.window: QCocoaWindow::QCocoaWindow QWidgetWindow(0x600000173060, name="centralwidgetWindow")
qt.qpa.window: QCocoaWindow::initialize QWidgetWindow(0x600000173060, name="centralwidgetWindow")
qt.qpa.drawing: Making <QNSView: 0x120f15b50; QCocoaWindow(0x600001270d10, window=QWidgetWindow(0x600000173060, name="centralwidgetWindow"))> layer-backed with <NSViewBackingLayer: 0x600002b39e90> due to being enabled by macOS
qt.qpa.window: QCocoaWindow::setGeometry QWidgetWindow(0x600000173060, name="centralwidgetWindow") QRect(0,0 100x30)
qt.qpa.window: QCocoaWindow::recreateWindowIfNeeded QWidgetWindow(0x600000173060, name="centralwidgetWindow") QFlagsQCocoaWindow::RecreationReason(ParentChanged|MissingWindow)
qt.qpa.window: Re-parenting <QNSView: 0x120f15b50; QCocoaWindow(0x600001270d10, window=QWidgetWindow(0x600000173060, name="centralwidgetWindow"))> from NSObject(0x0) to <QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))>
qt.qpa.window: Done re-parenting <QNSView: 0x120f15b50; QCocoaWindow(0x600001270d10, window=QWidgetWindow(0x600000173060, name="centralwidgetWindow"))> into <QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))>
qt.qpa.window: Moving <QNSView: 0x120f15b50; QCocoaWindow(0x600001270d10, window=QWidgetWindow(0x600000173060, name="centralwidgetWindow"))> from NSObject(0x0) to <QNSWindow: 0x12206a0c0; contentView=<QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))>>
qt.qpa.window: Done moving <QNSView: 0x120f15b50; QCocoaWindow(0x600001270d10, window=QWidgetWindow(0x600000173060, name="centralwidgetWindow"))> to <QNSWindow: 0x12206a0c0; contentView=<QNSView: 0x1220694e0; QCocoaWindow(0x60000127c210, window=QWidgetWindow(0x60000017e6a0, name="MainWindowWindow"))>>
qt.qpa.drawing: Backing properties changed for <QNSView: 0x120f15b50; QCocoaWindow(0x600001270d10, window=QWidgetWindow(0x600000173060, name="centralwidgetWindow"))>
qt.qpa.drawing: Updating <NSViewBackingLayer: 0x600002b39e90> content scale to 1
qt.qpa.cocoa.notifications: Forwarding NSViewFrameDidChangeNotification to QVector(QCocoaWindow(0x600001270d10, window=QWidgetWindow(0x600000173060, name="centralwidgetWindow")))
qt.qpa.window: QCocoaWindow::setMask QWidgetWindow(0x600000173060, name="centralwidgetWindow") QRegion(null)
qt.qpa.window: QCocoaWindow::QCocoaWindow QWidgetWindow(0x600000172dc0, name="widgetWindow")
qt.qpa.window: QCocoaWindow::initialize QWidgetWindow(0x600000172dc0, name="widgetWindow")
qt.qpa.drawing: Making <QNSView: 0x120f16130; QCocoaWindow(0x600001270c60, window=QWidgetWindow(0x600000172dc0, name="widgetWindow"))> layer-backed with <NSViewBackingLayer: 0x600002b39f50> due to being enabled by macOS -
wrote on 10 Dec 2024, 23:59 last edited by
the log is too log, I upload it here.
https://bugreports.qt.io/secure/attachment/169205/qt_log.txtand I also upload the test code.
https://bugreports.qt.io/secure/attachment/169186/test.zip
1/5