[Interest] iOS Objective-C callback block example connecting back to iOS Qt app?

Harri Pasanen harri at mpaja.com
Fri May 15 14:27:13 CEST 2015


Steps 1 & 2 are unnecessary.
You can just call your C++ function from the Objective-C++ code.

And by setting up you signal / slot registration correctly, you can even 
let Qt handle the threading issues,

What you describe is more akin to Java to Qt C++ call, with 
Objective-C++ it really is simple.

Harri

On 15/05/2015 14:17, Edward Sutton wrote:
> Harri,
>
> Thank you.
>
> I think I need to figure out how to:
>
> 1 - Pass in a function pointer to the Objective-C code.
> 2 - The Objective-C callback block calls the function pointer back 
> into the C++ code
> 3 - C++ code raises a Qt signal
> 4 - Qt client app receives signal
>
> And figure out any threading issues.
>
> -Ed
>
>
>
>> On May 15, 2015, at 1:48 AM, Harri Pasanen <harri at mpaja.com 
>> <mailto:harri at mpaja.com>> wrote:
>>
>> Actually it is trivial.
>>
>> Just rename your Objective-C .m to .mm to make it Objective-C++
>> Then you can just mix Qt code in the same source.
>>
>> So your successBlock could read:
>>
>>     successBlock:^(NDHTMLtoPDF *htmlToPDF) {
>>
>>         QString *result = QString::fromNSString([NSString 
>> stringWithFormat:@"HTMLtoPDF did succeed (%@ / %@)", htmlToPDF, 
>> htmlToPDF.PDFpath]);
>> qDebug() << result;
>>     }
>>
>> Only thing you may need to be aware of is threading, the success block
>> could be called from different thread you Qt code is running.
>>
>> Hope this helps,
>>
>> Harri
>>
>> On 14/05/2015 23:53, Edward Sutton wrote:
>>> Can anyone share an example on how to implement the asynchronous 
>>> return of a result from an Objective-C callback block to Qt?
>>>
>>> For example, see the “successBlock:” below which gets called back 
>>> asynchronously.
>>>
>>>     self.PDFCreator = [NDHTMLtoPDF createPDFWithHTML:(NSString*)html
>>>                                              baseURL:(NSURL*)baseUrl
>>>                                           pathForPDF:[@"~/Documents/hello-world.pdf" 
>>> stringByExpandingTildeInPath]
>>>                                             pageSize:kPaperSizeA4 
>>> margins:UIEdgeInsetsMake(10, 5, 10, 5)
>>>     successBlock:^(NDHTMLtoPDF *htmlToPDF) {
>>>
>>>         NSString *result = [NSString stringWithFormat:@"HTMLtoPDF 
>>> did succeed (%@ / %@)", htmlToPDF, htmlToPDF.PDFpath];
>>>         NSLog(@"%@",result);
>>>         self.resultLabel.text = result;
>>>
>>>     }
>>>     errorBlock:^(NDHTMLtoPDF *htmlToPDF) {
>>>         NSString *result = [NSString stringWithFormat:@"HTMLtoPDF 
>>> did fail (%@)", htmlToPDF];
>>>         NSLog(@"%@",result);
>>>         self.resultLabel.text = result;
>>>     }];
>>>
>>>
>>> Background:
>>> ————————
>>>
>>> I need to implement native iOS code to replace the missing QPrinter 
>>> functionality I used to convert HTML to a PDF report on Android, OS 
>>> X, Linux, and Windows.
>>>
>>> Unfortunately the Qt html-to-pdf functionality is implemented in 
>>> QPrinter.  This functionality is gone from Qt iOS since iOS has no 
>>> printer device support,  even though I am not accessing a printer 
>>> device from iOS.
>>>
>>> I found this project which seems to work:
>>>
>>> https://github.com/iclems/iOS-htmltopdf
>>>
>>> Objective-C interfacing to C++ is challenging.
>>>
>>> Thanks in advance for any tips,
>>>
>>> -Ed
>>> This email and any files transmitted with it from The Charles 
>>> Machine Works, Inc. are confidential and intended solely for the use 
>>> of the individual or entity to which they are addressed. If you have 
>>> received this email in error please notify the sender. Our company 
>>> accepts no liability for the contents of this email, or for the 
>>> consequences of any actions taken on the basis of the information 
>>> provided, unless that information is subsequently confirmed in 
>>> writing. Please note that any views or opinions presented in this 
>>> email are solely those of the author and do not necessarily 
>>> represent those of the company. Finally, the recipient should check 
>>> this email and any attachments for the presence of viruses. The 
>>> company accepts no liability for any damage caused by any virus 
>>> transmitted by this email.
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>> http://lists.qt-project.org/mailman/listinfo/interest
>
> This email and any files transmitted with it from The Charles Machine 
> Works, Inc. are confidential and intended solely for the use of the 
> individual or entity to which they are addressed. If you have received 
> this email in error please notify the sender. Our company accepts no 
> liability for the contents of this email, or for the consequences of 
> any actions taken on the basis of the information provided, unless 
> that information is subsequently confirmed in writing. Please note 
> that any views or opinions presented in this email are solely those of 
> the author and do not necessarily represent those of the company. 
> Finally, the recipient should check this email and any attachments for 
> the presence of viruses. The company accepts no liability for any 
> damage caused by any virus transmitted by this email.
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150515/9cdee7fc/attachment.html>


More information about the Interest mailing list