I have already spend 3 days on that when the same thing on Android took
me 5 minutes, so I think I'm not going to swizzle anything soon ;) I
might give it a try one day though. I believe that should be anyway a
part of qt API. 

Thanks all for your advice and comments 

Philippe. 

Le 29-05-2015 16:08, Ben Lau a écrit : 

> Depend on what kind of function you should to override. Just checked the 
> source code of QIOSViewController , shouldAutorotate is seem to be OK. 
> Moreover, Harri Pasanen has suggested swizzling, which could replace a method 
> and call the original one by the wrapper. 
> 
> On 29 May 2015 at 21:43, maitai <[email protected]> wrote:
> 
> I think you can do that because openUrl is the only method implemented in the 
> original QIOApplicationDelegate. So in fact you added 
> didFinishLaunchingWithOptions and replaced openUrl. But if there were other 
> methods (and QIOViewController has many), you would have been obliged to 
> duplicate them all, at least that's what I understand. Am I wrong? 
> 
> Le 29-05-2015 15:33, Ben Lau a écrit : 
> 
> You may override existing method just like what I did to openUrl and 
> didFinishLaunchingWithOptions on QIOSApplicationDelegate even you don't have 
> the header file. 
> 
> On 29 May 2015 at 21:25, maitai <[email protected]> wrote:
> 
> I tried but didn't succeed. If I understand well (which is far from being 
> certain), I can only add new methods or properties that way, not override 
> existing ones unless a protocol is defined that would allow me to create a 
> delegate on QIOViewController, but there is no as far as I can see. 
> 
> I might be wrong, though. I even hope so. 
> 
> Le 29-05-2015 15:18, Ben Lau a écrit : 
> 
> Why don't use categories that suggested by people here? 
> 
> On 29 May 2015 at 21:11, maitai <[email protected]> wrote:
> Finally got it working... with a bad hack
> 
> I cloned QIOSViewController.h and .mm from qt sources (and added qt's
> iOS headers in my include path, I already had core-private and
> gui-private in my pro files) and modified it to do what I want. I also
> had to add a lockedOrientation property to it for some mysterious
> reason...
> 
> At least it's doing what I need (i.e. ignore device rotation when I
> decide to). Of course it's a really bad hack and I'm still hoping
> someone can point me to a better solution.
> 
> Thanks
> Philippe.
> 
> Le 29-05-2015 11:24, maitai a écrit :
>> 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
>>>  [1]
>>>
>>> Or resort to something quite funky to replace existing methods:
>>> https://github.com/rentzsch/jrswizzle [2]
>>>
>>> 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 <[email protected]>
>>>> 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
>>>>>  [3]
>>>>> 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 [4]:24, Ben Lau a écrit :
>>>>>
>>>>>
>>>>>
>>>>> On 28 May 2015 at 02:07, maitai <[email protected]> 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 [5] 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 [6]
>>>>
>>>> That could be an answer - Let it be.
>>>>
>>>> Sincerely,
>>>> Robert
>>>> _______________________________________________
>>>> Interest mailing list
>>>> [email protected]
>>>> http://lists.qt-project.org/mailman/listinfo/interest [7]
>>>
>>> _______________________________________________
>>> Interest mailing list
>>> [email protected]
>>> http://lists.qt-project.org/mailman/listinfo/interest [7]
>> _______________________________________________
>> Interest mailing list
>> [email protected]
>> http://lists.qt-project.org/mailman/listinfo/interest [7]
> _______________________________________________
> Interest mailing list
> [email protected]
> http://lists.qt-project.org/mailman/listinfo/interest [7]

_______________________________________________
 Interest mailing list
 [email protected]
 http://lists.qt-project.org/mailman/listinfo/interest [7] 
_______________________________________________
 Interest mailing list
 [email protected]
 http://lists.qt-project.org/mailman/listinfo/interest [7]
 

Links:
------
[1]
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html
[2] https://github.com/rentzsch/jrswizzle
[3]
https://forum.qt.io/topic/48745/how-to-get-didfinishlaunchingwithoptions-called-in-ios-delegate/7
[4] tel:27-05-2015%2020
[5] http://appdelegate.mm
[6] https://bugreports.qt.io/browse/QTBUG-42123
[7] http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to