Results 1 to 2 of 2

Thread: Wrapping Qt classes strategy

  1. #1
    Join Date
    Mar 2009
    Posts
    39
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Wrapping Qt classes strategy

    I am studiying how to port existing applications to the Qt envirnoment. For this I need to wrap some of the QtClasses and I am undecided on what strategy to follow and without enough experience in Qt in fact I don't know even if they will work.

    Let's say I want to add a numeric identifier to any Widget (much like Windows does with controls) and I want also centralize the signals and events to translate to the existing protocol.

    I want something like this
    Qt Code:
    1. class MyWidget{
    2.  
    3. public:
    4. int idWidget;
    5.  
    6. mousePressEvent(QMouseEvent *me){DoMyGenericMousePressRoutine();}
    7.  
    8. void valueChanged(int v){DoMyValueChangedProcessing();}
    9.  
    10. };
    To copy to clipboard, switch view to plain text mode 

    And have for example a MyLineEdit having both MyControl and QLineEdit functionality.


    The question is how MyControl should embrace QWidgets in this case?
    Qt Code:
    1. A) Multiple inheritance:
    2. class MyLineEdit:public MyControl,virtual public QLineEdit{
    3.  
    4. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. B) Templates:
    2. template <class QtClass> class MyClass{
    3.  
    4. public:
    5. int idWidget;
    6.  
    7. mousePressEvent(QMouseEvent *me){DoMyGenericMousePressRoutine();}
    8.  
    9. void valueChanged(int v){DoMyValueChangedRoutine();}
    10.  
    11. };
    12.  
    13. MyClass<QLineEdit> MyLineEdit;
    To copy to clipboard, switch view to plain text mode 


    I have yet to make tests to see if these will work (hopefully this makes sense!), I don't know if the event handers and slots will be actually called being in these ways or there will be something i didn't foresee so I though I'd ask if there's people with experience or any ideas about this. Or maybe some other approach.

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Wrapping Qt classes strategy

    For the events I would install an event filter, possibly on the application object and then in the global filter I would provide the desired functionality based on the class of the widget that the event was meant for.

    As for id, you have two choices. Either reuse the "objectName" property and store the id there or use dynamic properties.

    So basically you don't need to subclass anything.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    thru (2nd June 2010)

Similar Threads

  1. Replies: 2
    Last Post: 13th March 2009, 11:23
  2. Professional Classes & Objects Structure
    By webstylemedia in forum Newbie
    Replies: 4
    Last Post: 4th August 2008, 10:50
  3. Adding nonQt classes to QtApplication
    By codebehind in forum Newbie
    Replies: 11
    Last Post: 23rd April 2007, 21:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.