You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openoffice.apache.org by Henry Tiquet Leyva <he...@gmail.com> on 2013/04/12 02:50:55 UTC

Programming OOoDraw and OOoImpress

Hello everyone,

I'm trying to do that:
http://wiki.openoffice.org/wiki/Programming_OOoDraw_and_OOoImpress#Giving_a_Name_to_the_Shape


and the connection is successful and the XComponentloader is instanciated
but when I add this part of code:

//get an instance of the spreadsheet
    Reference< XComponent > xcomponent =
rComponentLoader->loadComponentFromURL(
OUString::createFromAscii("private:factory/swriter"),
        OUString::createFromAscii("prueba"),
        0,
        Sequence < ::com::sun::star::beans::PropertyValue >());

I get that:

Connected sucessfully to the office
XComonentloader succesfully instanciated
Segmentation fault (core dumped)
make: *** [firstConnection_back.run] Error 139

I'm working in Ubuntu 12.04

I would like to know if the code have changed or if I need to add something
more.

Is possible that I haven't something installed in my computer?

Regards...

Re: Programming OOoDraw and OOoImpress

Posted by Henry Tiquet Leyva <he...@gmail.com>.
Did yuo add it to the code in http://ooo.pastebin.ca/2357487?
No, I didn't. I added it in my main code.

Thank you for that you told me in the above mail. I get it, but I got this
error because I didn't add the correct name of object, in your code it is
called xDoc, I just had to change xcomponent to xDoc. It was a problem of
inheritance.

Re: Programming OOoDraw and OOoImpress

Posted by Ariel Constenla-Haile <ar...@apache.org>.
On Sat, Apr 13, 2013 at 03:09:57PM -0500, Henry Tiquet Leyva wrote:
> Hello Ariel,
> 
> I added this at the code above:
> 
> css::uno::Reference < css::drawing::XDrawPagesSupplier >
> rDrawDoc(xcomponent, css::uno::UNO_QUERY_THROW);
> 
> // query the XDrawPages Interface
> css::uno::Reference < css::drawing::XDrawPages > rDrawPages =
> rDrawDoc->getDrawPages();
> 
> // query the XIndexAccess Interface
> css::uno::Reference< css::container::XIndexAccess >
> rPageIndexAccess(rDrawPages, css::uno::UNO_QUERY_THROW);
> 
> css::uno::Any DrawPage = rPageIndexAccess->getByIndex(0);
> 
> But now I get this error:
> error: 'xComponent' was not declared in this scope
> 
> I would like to know how to declare it.

Did you add it to the code in http://ooo.pastebin.ca/2357487?

Usually, in a client application, you access a document by loading it:
http://www.openoffice.org/api/docs/common/ref/com/sun/star/frame/XComponentLoader.html#loadComponentFromURL
loadComponentFromURL() returns a ::com::sun::star::lang::XComponent.
In that pastebin code, this is:

Reference < XComponent > xcomponent = rComponentLoader->loadComponentFromURL(
OUString::createFromAscii("private:factory/sdraw"),
OUString(RTL_CONSTASCII_USTRINGPARAM( "_blank" )), 
0, 
Sequence< ::com::sun::star::beans::PropertyValue>());

In the code in my attachment, as I wasn't going to use this
css::lang::XComponent interface, I queried for the
css::drawing::XDrawPagesSupplier directly, no need for an intermediate,
unused, variable. See code attached in this mail for a more complete
sample (you may want to translate the Java example in the SDK to C++ in
order to get used to Draw/Impress API).


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

Re: Programming OOoDraw and OOoImpress

Posted by Henry Tiquet Leyva <he...@gmail.com>.
Hello Ariel,

I added this at the code above:

css::uno::Reference < css::drawing::XDrawPagesSupplier >
rDrawDoc(xcomponent, css::uno::UNO_QUERY_THROW);

// query the XDrawPages Interface
css::uno::Reference < css::drawing::XDrawPages > rDrawPages =
rDrawDoc->getDrawPages();

// query the XIndexAccess Interface
css::uno::Reference< css::container::XIndexAccess >
rPageIndexAccess(rDrawPages, css::uno::UNO_QUERY_THROW);

css::uno::Any DrawPage = rPageIndexAccess->getByIndex(0);

But now I get this error:
error: 'xComponent' was not declared in this scope

I would like to know how to declare it.

Re: Programming OOoDraw and OOoImpress

Posted by Henry Tiquet Leyva <he...@gmail.com>.
Thank you!!! It is solved!
Now I get it. Only I had to change the cxx name file in the new Makefile
and now it is working perfectly.

Regards!


2013/4/12 Ariel Constenla-Haile <ar...@apache.org>

> On Fri, Apr 12, 2013 at 05:20:48PM -0500, Henry Tiquet Leyva wrote:
> > http://ooo.pastebin.ca/2357487
> >
> > I am sorry, here is it, I think it is better like this.
>
> at first sight, there is nothing wrong (though the code is old).
>
> How are you building this code? It tries to connect to a running office
> listening on port 2083, is the office running and listening?
>
> > >> > I have done all you told me but I have the error yet.
> > >> > I searched in Internet and it said that generally such errors are
> > >> caused by
> > >> > addressing non-existent/allocated memory.
>
> when working with css::uno::Reference, you may get a segmentation fault
> with the dereference operator, if you don't check first with
> BaseReference::is(), but your code does the check, and according to your
> previous mail, it prints "XComponentloader successfully instanciated\n".
>
> Wild guessing, I assume your program is not bootstrapping the remote
> counterpart, thus the reference to the desktop is invalid. In order to
> know where your program is crashing, build with debug symbols, run it
> inside the debugger, and after crash look at the backtrace.
>
> Alternatively try with the attached code, it has an SDK Makefile, you
> need to set the SDK environment in order to build it; and it uses the
> simple bootstrap mechanism, so you get rid of bootstrapping an office
> listening on a port. To build it and run:
>
> source <path to>/setsdkenv_unix.sh
> make DEBUG=yes PRJ=$OO_SDK_HOME HelloDraw.run
>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>

Re: Programming OOoDraw and OOoImpress

Posted by Ariel Constenla-Haile <ar...@apache.org>.
On Fri, Apr 12, 2013 at 05:20:48PM -0500, Henry Tiquet Leyva wrote:
> http://ooo.pastebin.ca/2357487
> 
> I am sorry, here is it, I think it is better like this.

at first sight, there is nothing wrong (though the code is old).

How are you building this code? It tries to connect to a running office
listening on port 2083, is the office running and listening? 

> >> > I have done all you told me but I have the error yet.
> >> > I searched in Internet and it said that generally such errors are
> >> caused by
> >> > addressing non-existent/allocated memory.

when working with css::uno::Reference, you may get a segmentation fault
with the dereference operator, if you don't check first with
BaseReference::is(), but your code does the check, and according to your
previous mail, it prints "XComponentloader successfully instanciated\n".

Wild guessing, I assume your program is not bootstrapping the remote
counterpart, thus the reference to the desktop is invalid. In order to
know where your program is crashing, build with debug symbols, run it
inside the debugger, and after crash look at the backtrace.

Alternatively try with the attached code, it has an SDK Makefile, you
need to set the SDK environment in order to build it; and it uses the
simple bootstrap mechanism, so you get rid of bootstrapping an office
listening on a port. To build it and run:

source <path to>/setsdkenv_unix.sh
make DEBUG=yes PRJ=$OO_SDK_HOME HelloDraw.run


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

Re: Programming OOoDraw and OOoImpress

Posted by Henry Tiquet Leyva <he...@gmail.com>.
http://ooo.pastebin.ca/2357487

I am sorry, here is it, I think it is better like this.


2013/4/12 Henry Tiquet Leyva <he...@gmail.com>

>
>
>
> 2013/4/12 Ariel Constenla-Haile <ar...@apache.org>
>
>> Hi Henry,
>>
>> On Fri, Apr 12, 2013 at 04:53:54PM -0500, Henry Tiquet Leyva wrote:
>> > Hi Ariel,
>> >
>> > I have done all you told me but I have the error yet.
>> > I searched in Internet and it said that generally such errors are
>> caused by
>> > addressing non-existent/allocated memory.
>> >
>> > Is posible that I am using some wrong variable?
>>
>> I'll need to see the whole code. Can't you upload it somewhere?
>>
>>
>> Regards
>> --
>> Ariel Constenla-Haile
>> La Plata, Argentina
>>
>
>

Re: Programming OOoDraw and OOoImpress

Posted by Henry Tiquet Leyva <he...@gmail.com>.
2013/4/12 Ariel Constenla-Haile <ar...@apache.org>

> Hi Henry,
>
> On Fri, Apr 12, 2013 at 04:53:54PM -0500, Henry Tiquet Leyva wrote:
> > Hi Ariel,
> >
> > I have done all you told me but I have the error yet.
> > I searched in Internet and it said that generally such errors are caused
> by
> > addressing non-existent/allocated memory.
> >
> > Is posible that I am using some wrong variable?
>
> I'll need to see the whole code. Can't you upload it somewhere?
>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>

Re: Programming OOoDraw and OOoImpress

Posted by Ariel Constenla-Haile <ar...@apache.org>.
Hi Henry,

On Fri, Apr 12, 2013 at 04:53:54PM -0500, Henry Tiquet Leyva wrote:
> Hi Ariel,
> 
> I have done all you told me but I have the error yet.
> I searched in Internet and it said that generally such errors are caused by
> addressing non-existent/allocated memory.
> 
> Is posible that I am using some wrong variable?
 
I'll need to see the whole code. Can't you upload it somewhere?


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

Re: Programming OOoDraw and OOoImpress

Posted by Henry Tiquet Leyva <he...@gmail.com>.
Hi Ariel,

I have done all you told me but I have the error yet.
I searched in Internet and it said that generally such errors are caused by
addressing non-existent/allocated memory.

Is posible that I am using some wrong variable?


2013/4/11 Ariel Constenla-Haile <ar...@apache.org>

> Hi Henry,
>
> On Thu, Apr 11, 2013 at 07:50:55PM -0500, Henry Tiquet Leyva wrote:
> > Hello everyone,
> >
> > I'm trying to do that:
> >
> http://wiki.openoffice.org/wiki/Programming_OOoDraw_and_OOoImpress#Giving_a_Name_to_the_Shape
> >
> >
> > and the connection is successful and the XComponentloader is
> > instanciated but when I add this part of code:
> >
> > //get an instance of the spreadsheet Reference< XComponent
> > > xcomponent = rComponentLoader->loadComponentFromURL(
> > > OUString::createFromAscii("private:factory/swriter"),
> > > OUString::createFromAscii("prueba"),
>
> Try with "_default", or "_blank"
> see
>
> http://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Handling_Documents#Target_Frame
>
> By the way, createFromAscii is expensive for ASCII string literals,
> better use OUString(RTL_CONSTASCII_USTRINGPARAM( "_default" ))
>
> http://www.openoffice.org/api/docs/cpp/ref/def-all.html#RTL_CONSTASCII_USTRINGPARAM
>
> > Connected sucessfully to the office
> > XComonentloader succesfully instanciated
> > Segmentation fault (core dumped)
>
> This shouldn't crash. Is it the office code that crashes, or your client
> application not catching the exception thrown by loadComponentFromURL?
> Please try surrounding the code with a try-catch; if it still crashes,
> then open a bug.
>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>

Re: Programming OOoDraw and OOoImpress

Posted by Ariel Constenla-Haile <ar...@apache.org>.
Hi Henry,

On Thu, Apr 11, 2013 at 07:50:55PM -0500, Henry Tiquet Leyva wrote:
> Hello everyone,
> 
> I'm trying to do that:
> http://wiki.openoffice.org/wiki/Programming_OOoDraw_and_OOoImpress#Giving_a_Name_to_the_Shape
> 
> 
> and the connection is successful and the XComponentloader is
> instanciated but when I add this part of code:
> 
> //get an instance of the spreadsheet Reference< XComponent
> > xcomponent = rComponentLoader->loadComponentFromURL(
> > OUString::createFromAscii("private:factory/swriter"),
> > OUString::createFromAscii("prueba"),

Try with "_default", or "_blank"
see
http://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Handling_Documents#Target_Frame

By the way, createFromAscii is expensive for ASCII string literals,
better use OUString(RTL_CONSTASCII_USTRINGPARAM( "_default" ))
http://www.openoffice.org/api/docs/cpp/ref/def-all.html#RTL_CONSTASCII_USTRINGPARAM

> Connected sucessfully to the office
> XComonentloader succesfully instanciated
> Segmentation fault (core dumped)

This shouldn't crash. Is it the office code that crashes, or your client
application not catching the exception thrown by loadComponentFromURL?
Please try surrounding the code with a try-catch; if it still crashes,
then open a bug.


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina