0.5 C
New York
Sunday, February 23, 2025

goal c – Qt6 IOS QML QIOSApplicationDelegate begins delegate however Major.qml not seen (display is black)


Ive spent many hours attempting to get a easy QML IOS software to begin the UIApplication delegate in addition to begin and show the Major.qml element for a bigger app I wish to create.

Im utilizing Qt 6.8.1 on MacOS Sonoma 14.6.1, Qt Creator 15.0.0
Ive tried operating it on each the IOS Simulator in addition to an Iphone Gadget w/identical end result.

The issue is that every thing appears to work besides that the Major.qml shouldn’t be displaying.
The Display screen is simply black. I can shut the app and open it and the UIApplication delegates
are getting known as as anticipated however the display is at all times black. Ive tried a number of different
options none of which I’ve been capable of get factor to work accurately.

Ive included the output once I run it so you may see issues seem like working
as anticipated aside from the visible show.

Any assist and/or ideas are appreciated.
Thanks!

Major.qml:

import QtQuick
import QtQuick.Window
import QtQuick.Controls

ApplicationWindow {
    width: 640
    top: 480
    seen: true
    coloration: "inexperienced"

    Element.onCompleted: {
        console.log("Major.qml Accomplished")
    }

    onVisibleChanged: console.log("Major.qml: seen: " + seen)

    Textual content {
        textual content: "My Utility"
        coloration: "white"
        anchors.centerIn: father or mother
        font.pixelSize: 26
    }
}

AppDelegate.h:

#import 

@interface QIOSApplicationDelegate : UIResponder 
@property (sturdy, nonatomic) UIWindow *window;
@finish

AppDelegate.mm

// AppDelegate.mm
#import "AppDelegate.h"

extern void setContinueLaunchingQML();

@implementation QIOSApplicationDelegate

- (void)applicationDidFinishLaunching:(UIApplication *)software {
    NSLog(@"------------ App applicationDidFinishLaunching");
}

- (BOOL)software:(UIApplication *)software didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSLog(@"==== didFinishLaunchingWithOptions");

    setContinueLaunchingQML();

    NSLog(@"==== applicationDidFinishLaunching return YES ====");
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)software {
    NSLog(@"IOS_APP_DEL: applicationWillResignActive");
}
- (void)applicationDidEnterBackground:(UIApplication *)software {
    NSLog(@"IOS_APP_DEL: applicationDidEnterBackground");
}
- (void)applicationWillEnterForeground:(UIApplication *)software {
    NSLog(@"IOS_APP_DEL: applicationWillEnterForeground");
}
- (void)applicationDidBecomeActive:(UIApplication *)software {
    NSLog(@"IOS_APP_DEL: applicationDidBecomeActive");
}
- (void)applicationWillTerminate:(UIApplication *)software {
}
@finish

primary.cpp:

// primary.cpp
#embrace 
#embrace 
#embrace 
#embrace 

static bool waiting_for_ios_delegate_ = true;

int primary(int argc, char *argv[])
{
    qDebug() << "MAIN CPP begin";

    whereas(waiting_for_ios_delegate_) {
        sleep(1);
        qApp->processEvents();
    }

    qDebug() << "Proceed primary cpp Startup...";

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    QQmlComponent element(&engine);
    element.loadFromModule("iosDelegate", "Major");
    if (element.isReady()) {
        qDebug() << "Element Major.qml READY...now create it";
        if (!element.create()) {
            qWarning() << "ERROR - Major.qml didn't create";
            _exit(1);
        }
    }
    else {
        qWarning() << "ERROR - Major.qml shouldn't be prepared - " << element.errorString();
        _exit(1);
    }

    qDebug() << "exec()";
    return app.exec();
}

void setContinueLaunchingQML()
{
    qDebug() << "setContinueLaunchingQML";
    waiting_for_ios_delegate_ = false;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)

venture(iosDelegate VERSION 0.1 LANGUAGES CXX OBJCXX)

find_package(Qt6 REQUIRED COMPONENTS
    Core
    Qml
    Gui
    Fast
    QuickControls2
    Widgets)

qt_standard_project_setup(REQUIRES 6.5)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++ -fobjc-arc
    -I./*.h
    -iwithprefix /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/embrace/
    -iwithprefix /Library/Developer/CommandLineTools/SDKs/MacOSX15.1.sdk/System/Library/Frameworks/
    ")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
    -framework Basis
    -framework UIKit
")

if(APPLE)
    set(APPLE_SDK_TOP /Purposes/Xcode.app/Contents/Developer/Platforms)
    set(IOS_SYS_LIB_FRAMEWORK System/Library/Frameworks)

    if(CMAKE_OSX_SYSROOT STREQUAL "iphonesimulator")
        set(IOS_PLATFORM iPhoneSimulator)
    elseif (CMAKE_OSX_SYSROOT STREQUAL "iphoneos")
        set(IOS_PLATFORM iPhoneOS)
    else()
        warning(IOS_PLATFORM NOT FOUND)
    endif()
endif(APPLE)

qt_add_executable(appiosDelegate
    primary.cpp
    AppDelegate.h
    AppDelegate.mm
)

qt_add_qml_module(appiosDelegate
    URI iosDelegate
    VERSION 1.0
    QML_FILES
        Major.qml
)

set_target_properties(appiosDelegate PROPERTIES
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

target_link_libraries(appiosDelegate
    PRIVATE
    Qt6::Core
    Qt6::Qml
    Qt6::Fast
    Qt6::Gui
    Qt6::QuickControls2
    Qt6::Widgets
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(${TARGET})
endif()

set(CMAKE_OSX_INFOPLIST_FILE "${CMAKE_CURRENT_LIST_DIR}/Information.plist")
set(MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/Information.plist")

embrace(GNUInstallDirs)
set up(TARGETS appiosDelegate
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

Output:

2025-01-17 11:05:07.432 appiosDelegate[50772:16574720] ==== didFinishLaunchingWithOptions
setContinueLaunchingQML
2025-01-17 11:05:07.434 appiosDelegate[50772:16574720] ==== applicationDidFinishLaunching return YES ====
MAIN CPP begin
Proceed primary cpp Startup...
Element Major.qml READY...now create it
qml: Major.qml: seen: true
qml: Major.qml Accomplished
exec()
2025-01-17 11:05:08.229 appiosDelegate[50772:16574720] IOS_APP_DEL: applicationDidBecomeActive
2025-01-17 11:12:39.336 appiosDelegate[50772:16574720] IOS_APP_DEL: applicationWillResignActive
2025-01-17 11:12:39.972 appiosDelegate[50772:16574720] IOS_APP_DEL: applicationDidEnterBackground
2025-01-17 11:12:44.486 appiosDelegate[50772:16574720] IOS_APP_DEL: applicationWillEnterForeground
2025-01-17 11:12:44.764 appiosDelegate[50772:16574720] IOS_APP_DEL: applicationDidBecomeActive

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles