[Kde-bindings] Fw: [Qyoto] Casting QObjects

Dimitar Dobrev dpldobrev at yahoo.com
Thu May 24 23:08:27 UTC 2012


Sounds great. :)
I'm glad it worked for you. I'd be happy to answer other questions you might have, if time permits. For now good luck with your work.



________________________________
 From: Mach <metator.pt at gmail.com>
To: Dimitar Dobrev <dpldobrev at yahoo.com>; KDE bindings for other programming languages <kde-bindings at kde.org> 
Sent: Friday, May 25, 2012 1:38 AM
Subject: Re: [Kde-bindings] Fw:  [Qyoto] Casting QObjects
 

Thanks, 

Qt.qobject_cast<> does the job. I won't promise you anything
    but i might be able to help in testing (and spreading the word, of
    course!). I still need to get acquainted to Qt and Qyoto. I'm
    investigating gui libraries for csharp that work at least in Windows
    and Mac's. If it gets approved, i'll be glad do help in testing.

Regards

Em 24-05-2012 23:03, Dimitar Dobrev escreveu: 
You're welcome. :) I hope you will join our community, we could definitely use any kind of help: development, testing, popularisation among developers, etc. 
>
>
>I've just checked "qt_rubberband" in a C++ Qt project. The debugger shows it is as a QObject in an empty QMainWindow, i.e. the same as in your C# code. This probably means that Qyoto is in no error in this case. About what "qt_rubberband" is, here is an explanation -
http://www.qtcentre.org/threads/34998-qt_rubberband-blocking-events-of-pushbutton?p=161726#post161726.
>
>
>
>Anyway, you may try casting it using the Qt.qobject_cast<> static method. Unfortunately, even if this works, I do not yet know a way to test if such an object is of a certain type (QWidget in this case).
>
>
>
>
>________________________________
> From: Mach <metator.pt at gmail.com>
>To: Dimitar Dobrev <dpldobrev at yahoo.com>; KDE bindings for other programming languages <kde-bindings at kde.org> 
>Sent: Friday, May 25, 2012 12:38 AM
>Subject: Re: [Kde-bindings] [Qyoto] Casting QObjects
> 
>
>Hi Dimitar, 
>
>Thank you for your quick reply. Well, i take
                          back what i said about traditional casting in
                          C#. Seems like this qt_rubberband object is
                          somewhat special (i don't have much experience
                          in Qt). For instance, following my example
                          this line of code returns null: QObject
                          rubberBand =
                          win.FindChild<QObject>("qt_rubberband");
>
>What i really find strange though, is that
                          qt_rubberband is considered to be only a
                          QObject. Shouldn't it be a QRubberBand (which
                          is a QWidget...)?
>
>Regards
>
>PS: I take this opportunity to thank you (and
                          also Steven Boswell regarding building Qyoto
                          in Windows) for making Qt available to
                          csharpers. 
>
>Em 24-05-2012 21:42, Dimitar Dobrev escreveu: 
>Hi, Mach,
>>
>>
>>On my machine your sample behaves the same way with the addition that traditional casting (that is, replacing 
>>
>>QWidget widget = (QWidget) child.MetaObject().Cast(child);
>>
>>
>>with
>>
>>
>>QWidget widget = (QWidget) child;
>>
>>
>>work as well). Apparently There is a bug in the IsWidgetType function because it allows the "qt_rubberband" which the debugger shows as a QObject only, to pass. However, "if (child is QWidget)" works properly so you can use that.
>>
>>
>>
>>
>>________________________________
>> From: Mach <metator.pt at gmail.com>
>>To: Kde-bindings at kde.org 
>>Sent: Thursday, May 24, 2012 10:54 PM
>>Subject: [Kde-bindings] [Qyoto] Casting QObjects
>> 
>>Hi all,
>>
>>I've managed to compile qyoto on
                                  windows and now i'm doing some test
                                  applications to try it out. I'm having
                                  trouble trying to downcast QObjects.
                                  Traditional casting in C# does not
                                  work, but i was expecting that. So i
                                  started to look for something that
                                  could perform a cast and found the
                                  method Cast(QObject) in QMetaObject
                                  but it's not working always. Below is
                                  an example application that tries to
                                  cast all the children of the main
                                  window to widgets. Notice that i
                                  previously check if the object is a
                                  widget type:
>>
>>using System;
>>using Qyoto;
>>
>>namespace QtTest {
>>    class Program {
>>        [STAThread]
>>        static void Main(string[]
                                  args) {
>>            QApplication app = new
                                  QApplication(args);
>>            QMainWindow win = new
                                  QMainWindow();
>>            QPushButton btn = new
                                  QPushButton(win);
>>            win.WindowTitle = "Demo
                                  Application";
>>            win.Show();
>>            foreach (QObject child in
                                  win.Children()) {
>>                if
                                  (child.IsWidgetType()) {
>>                    try {
>>                        QWidget widget
                                  = (QWidget)
                                  child.MetaObject().Cast(child);
>>                       
                                  Console.WriteLine("Cast succeeded.
                                  It's now a " + widget.GetType().Name);
>>                    } catch
                                  (InvalidCastException e) {
>>                       
                                  Console.WriteLine(child.ObjectName + "
                                  of type " +
                                  child.MetaObject().ClassName() +
>>                                     
                                      " cannot be cast to QWidget");
>>                    }
>>                }
>>            }
>>            QApplication.Exec();
>>        }
>>    }
>>}
>>
>>The output on the console is:
>>
>>qt_rubberband of type QRubberBand
                                  cannot be cast to QWidget
>>Cast succeeded. It's now a QPushButton
>>
>>I suspect this has something to do
                                  with the fact that qt_rubberband was
                                  created on the unmanaged side, whereas
                                  QPushButton was created by the managed
                                  side. I also tried calling
                                  QWidget.StaticMetaObject.Cast(QObject)
                                  but it's always returning null.
>>
>>Can someone help me out solving this
                                  problem?
>>
>>Thanks in advance. Regards
>>
>>
>>_______________________________________________
>>Kde-bindings mailing list
>>Kde-bindings at kde.org
>>https://mail.kde.org/mailman/listinfo/kde-bindings
>>
>>
>>
>>
>>
>>_______________________________________________
Kde-bindings mailing list Kde-bindings at kde.org https://mail.kde.org/mailman/listinfo/kde-bindings 
>
>
>
>
>
>
>
>_______________________________________________
Kde-bindings mailing list Kde-bindings at kde.org https://mail.kde.org/mailman/listinfo/kde-bindings 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20120524/50f81570/attachment-0001.html>


More information about the Kde-bindings mailing list