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

Melton, Ryan rmelton at ball.com
Fri Feb 12 23:06:16 UTC 2010


Here is a patch file that seems to handle the ExtraSelection cursor() issue.   I'll leave it to Richard for a more general solution.

Ryan
	
P.S> Did the patches for Windows I sent look good?

-----Original Message-----
From: Richard Dale [mailto:rdale at foton.es] 
Sent: Friday, February 12, 2010 9:30 AM
To: KDE bindings for other programming languages
Subject: Re: [Kde-bindings] ruby binding and Qt::TextEdit::ExtraSelection

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.
_______________________________________________
Kde-bindings mailing list
Kde-bindings at kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings



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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_extraselection_cursor.patch
Type: application/octet-stream
Size: 865 bytes
Desc: fix_extraselection_cursor.patch
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20100212/537ff07f/attachment.obj>


More information about the Kde-bindings mailing list