[Interest] Qt/iOS subclassing and/or delegating

maitai maitai at virtual-winds.org
Fri May 29 07:38:00 CEST 2015


 

Thanks Ben for your reply 

After much digging I made some progress but I am still looking for a way
to temporary lock screen auto rotation. 

I have created my own app delegate to catch openUrl(), and surprisingly
it works. I register my app delegate from main.cpp by calling something
like this: 

void QtAppDelegateInitialize ()

{

 QtAppDelegate *appDelegate = (QtAppDelegate *)[[UIApplication
sharedApplication] delegate];

 [[UIApplication sharedApplication] setDelegate:[QtAppDelegate
sharedQtAppDelegate]];

 NSLog(@"Created a new appdelegate");

}

I then found this very interesting post:
https://forum.qt.io/topic/48745/how-to-get-didfinishlaunchingwithoptions-called-in-ios-delegate/7
which links to this bug report: QTBUG-38184. 

First question: I am now wondering how my delegate can possibly work
since it seems I can have only one delegate... so what happened to
QIOSApplicationDelegate?

I then tried various things to add yet another delegate this time based
on UINavigationControllerDelegate, but although after much sweat it
seems to load, the various methods I am trying to override are never
called when I rotate the device. 

Could it be that I should instead modify/interface
QIOSApplicationDelegate itself and not try to create my own delegates? 

A bit confused at this point, I admit ;) 

Thanks for any tip 

Philippe Lelong 

Le 27-05-2015 20:24, Ben Lau a écrit : 

> On 28 May 2015 at 02:07, maitai <maitai at virtual-winds.org> wrote:
> 
>> Hello all,
>> 
>> I've started to port on iOS and need to override some methods, like we
>> do easily through Java on Qt/Android. I succeeded to implement an
>> appDelegate in objective-C that works for some events like openURL and
>> such, but for instance I also need to lock automatic screen rotation in
>> some circumstances (but not always).
> 
> Objective-C has a feature to replace the original method of a class. So you may just override the method you needed (In case it don't break Qt) 
> Customizing Existing Classes [2] 
> 
> Example Code: 
> quickios/appdelegate.mm at 0b067e17dc13b8533ca3f7dd574d7e81ea17a015 · benlau/quickios [3] 
> 
> I have tested to override openURL and didFinishLaunchingWithOptions of AppDelegate with Qt 5.4.1. This method works. 
> 
>> I read that I should somehow override "bool
>> UINavigationController::shouldRotate()"
> 
> Never tried. But should be worth to try? I am also be interested with your result. 
> 
>> Should I reimp (subclass?) UINavigationController and how? Or is there a
>> way to create a new delegate or even better to extend my current
>> appDelegate?
> 
>> I'm new to Objective-C as you can guess... Any clue would be really
>> appreciated :)
>> 
>> Thanks
>> Philippe Lelong
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest [1]

 

Links:
------
[1] http://lists.qt-project.org/mailman/listinfo/interest
[2]
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html
[3]
https://github.com/benlau/quickios/blob/0b067e17dc13b8533ca3f7dd574d7e81ea17a015/examples/quickiosexample/appdelegate.mm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150529/eb120939/attachment.html>


More information about the Interest mailing list