[Kde-bindings] ruby binding and Qt::TextEdit::ExtraSelection

Richard Dale rdale at foton.es
Fri Feb 12 16:30:20 UTC 2010


On Thursday 11 February 2010 08:10:54 pm Melton, Ryan wrote:
> Richard -
> 
> 
> 
> I've found the root cause to Jason's problem in the email below, but I'm
> not sure how to fix it.   The root cause is that the memory address of a
> class is the same as the memory address of the first data member of that
> class.
> 
> 
> 
> For example from qtextedit.h here is the definition of ExtraSelection:
> 
> 
> 
>     struct ExtraSelection
> 
>     {
> 
>         QTextCursor cursor;
> 
>         QTextCharFormat format;
> 
>     };
> 
> 
> 
> Now here is some ruby code that tries to use it:
> 
> 
> 
> my_object = Qt::TextEdit::ExtraSelection.new
> 
> puts my_object.cursor.class
> 
> 
> 
> Fails and returns my_object instead of a new ruby object wrapping the
> Qt::TextCursor.
> 
> 
> 
> But,
> 
> 
> 
> my_object = Qt::TextEdit::ExtraSelection.new
> 
> puts my_object.format.class
> 
> 
> 
> Works and returns a Qt::TextCharFormat because format is the second data
> member in the class and has a different memory address from the class
> itself.
> 
> 
> 
> The problem occurs in marshall_basetypes.h : void
> marshall_to_ruby<SmokeClassWrapper>(Marshall *m) when getPointerObject is
> called with a memory address that is the same as the memory address of the
> Qt::TextEdit::ExtraSelection class.
> 
> 
> 
> Any ideas?
That's an interesting bug, but it sounds quite tricky to fix. 

If getPointerObject() returns a Ruby instance that isn't of the expected Ruby 
class, it sounds as though it should just wrap the C++ instance (QTextCursor 
cursor in this case), as another Ruby instance. Then we would need to make 
sure that both of the different Ruby instances wrapping different C++ things at 
the same address wouldn't try to free it twice when they were garbage 
collected.

-- Richard

> 
> 
> 
> From: Thomas, Jason M (Software) [mailto:jmthomas at ball.com]
> Sent: Monday, February 08, 2010 2:40 PM
> To: kde-bindings at kde.org
> Subject: [Kde-bindings] ruby binding and Qt::TextEdit::ExtraSelection
> 
> 
> 
> I'm having problems using Qt::TextEdit::ExtraSelection under ruby. The
> following code shows the problem:
> 
> 
> 
>   class MyTextEdit < Qt::TextEdit
> 
>     def highlight
> 
>       selection = Qt::TextEdit::ExtraSelection.new
> 
>       selection.cursor = textCursor()
> 
>       STDOUT.puts "selection.cursor:#{selection.cursor}
> textCursor:#{textCursor()}"
> 
>     end
> 
>   end
> 
> 
> 
> When instantiating MyTextEdit and calling highlight the following output is
> printed:
> 
>     selection.cursor:#<Qt::TextEdit::ExtraSelection:0x36c1968>
> textCursor:#<Qt::TextCursor:0x36bebd8>
> 
> 
> 
> For some reason when I try to set the cursor property it runs but doesn't
> appear to actually change the underlying property. This class is different
> from most Qt classes in that it doesn't have explicit getter and setter
> methods. I don't know if that is playing a role or not.
> 
> 
> 
> BTW: What I'm trying to accomplish is to highlight and unhighlight
> individual lines in the TextEdit and this looked like the recommended way
> to do it.
> 
> 
> 
> Jason
> 
> 
> 
> This message and any enclosures are intended only for the addressee. 
> Please notify the sender by email if you are not the intended recipient. 
> If you are not the intended recipient, you may not use, copy, disclose, or
> distribute this message or its contents or enclosures to any other person
> and any such actions may be unlawful.  Ball reserves the right to monitor
> and review all messages and enclosures sent to or from this email address.
> 
> 
> 
> This message and any enclosures are intended only for the addressee. 
> Please notify the sender by email if you are not the intended recipient. 
> If you are not the intended recipient, you may not use, copy, disclose, or
> distribute this message or its contents or enclosures to any other person
> and any such actions may be unlawful.  Ball reserves the right to monitor
> and review all messages and enclosures sent to or from this email address.



More information about the Kde-bindings mailing list