[Interest] Qt/iOS subclassing and/or delegating

maitai maitai at virtual-winds.org
Fri May 29 11:24:45 CEST 2015


I had a look at QT sources... Basically what I want to do is override 
QIOSViewController:shouldAutorotate.

I tried
@interface MyIOSViewController : QIOSViewController
@end
@implementation MyIOSViewController
- (BOOL) shouldAutorotate {
     NSLog(@"Inside shouldAutorotate");
     return NO;
}

It compiles and does not crash (I import QIOSViewController.h), but that 
all it does...


Le 29-05-2015 10:23, Harri Pasanen a écrit :
> Compared to C++, Objective-C is very dynamic language and you can do
> many things at runtime.
> 
> So you can add methods to existing classes using categories:
> https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html
> 
> Or resort to something quite funky to replace existing methods:
> https://github.com/rentzsch/jrswizzle
> 
> As to your original question, rotation handling is surprisingly tricky
> even in pure Objective-C if you want to conditionally rotate.   For
> instance iOS 8.3 broke some of my code handling that which had worked
> fine since iOS 6, pure Objective-C.
> 
> I don't know how Qt hooks into it.
> 
> Harri
> 
> On 29/05/2015 09:41, Robert Iakobashvili wrote:
>> On Fri, May 29, 2015 at 8:38 AM, maitai <maitai at virtual-winds.org> 
>> wrote:
>>> 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
>>> 
>>> Example Code:
>>> quickios/appdelegate.mm at 0b067e17dc13b8533ca3f7dd574d7e81ea17a015 ·
>>> benlau/quickios
>>> 
>>> 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
>> Dear Philippe,
>> 
>> Please see the reply Tor Arne inside
>> 
>> https://bugreports.qt.io/browse/QTBUG-42123
>> 
>> That could be an answer - Let it be.
>> 
>> Sincerely,
>> Robert
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list